简体   繁体   English

C ++表达式模板的教程和介绍

[英]Tutorials and Introductions to C++ Expression Templates

What are good introductions to the creation of C++ expression template systems? 有什么好的介绍来创建C ++表达式模板系统? I would like to express arithmetic on user defined types while avoiding temporary values (which may be large), and to learn how to do this directly rather than applying an existing library. 我想表达对用户定义类型的算法,同时避免临时值(可能很大),并学习如何直接执行此操作而不是应用现有库。

I have found Todd Veldhuizen's original paper and an example from the Josuttis C++ Templates book , and an article by Kreft & Langer . 我找到了Todd Veldhuizen的原始论文Josuttis C ++模板书中的一个例子,以及Kreft&Langer的一篇文章。 It is mentioned in Lecture 6 of a course on Modern C++ , referring back to Josuttis.The POOMA library background introduces expression templates nicely. 现代C ++课程的第6讲中提到了Josuttis.POOMA库背景很好地介绍了表达模板。

I am looking for simple , clear expositions. 我正在寻找简单明了的论述。

I found Expression Templates Demystified to be fairly well explained. 我发现Expression Templates Demystified得到了相当好的解释。 It starts off by showing how to implement mathematical expressions without templates and shows the basic building blocks and concepts. 首先介绍如何在没有模板的情况下实现数学表达式,并展示基本构建块和概念。

The second part of the article shows how to refactor the initial implementation to use templates instead for improved performance and reduced code. 本文的第二部分展示了如何重构初始实现以使用模板来改进性能和减少代码。

IMO, the article is a good alternative to the expression template chapter in 'C++ Templates: The Complete Guide'. IMO,这篇文章是“C ++模板:完整指南”中表达模板章节的一个很好的替代品。

You should get a copy of C++ Templates: The Complete Guide . 您应该获得C ++模板的副本:完整指南

The code example to which you link doesn't have the accompanying text, which is quite helpful (the chapter on expression templates is 22 pages long). 您链接的代码示例没有附带的文本,这非常有用(表达式模板的章节长度为22页)。 Without the text, all you have is code without any comments or explanation as to what it does and how and why it does it. 没有文本,你所拥有的只是代码,没有任何评论或解释它的作用以及它是如何以及为什么这样做的。

I strongly encourage to look up Eric Niebler Boost.Proto library. 我强烈建议查阅Eric Niebler Boost.Proto库。 A very fine introduction materials can be found over C++-next : 可以在C ++上找到非常精细的介绍材料 - 下一篇:

http://cpp-next.com/archive/2010/08/expressive-c-introduction/ http://cpp-next.com/archive/2010/08/expressive-c-introduction/

and his talk at boost'con 2010 is also very interesting 他在boost'con 2010上的演讲也非常有趣

for what you want to do, you should look at the code of Boost.ublas as it does exactly that. 对于你想要做的事情,你应该看看Boost.ublas的代码,因为它确实如此。

Start with the file vector.hpp and then go back into the hierarchy (parents of vector<> ). 从文件vector.hpp开始,然后返回到层次结构( vector<>父项)。 Matrices are a bit more complex but the mechanisn is the same. 矩阵有点复杂,但机制是相同的。

Now I may advise not to try to reproduce the complexity of the library as a first try, like ublas_expression and things like that. 现在我可能建议不要尝试重现库的复杂性作为第一次尝试,比如ublas_expression和类似的东西。 You can do it simpler by making your type the base object and then implement a binary operator. 您可以通过将类型作为基础对象然后实现二元运算符来更简单地完成此操作。

Look here too: http://www.bnikolic.co.uk/blog/cpp-expression-minimal.html 请看这里: http//www.bnikolic.co.uk/blog/cpp-expression-minimal.html

You've got all the sources except for the scientific c++ book, which is really just the original paper (wrt to this topic anyway) and is pretty out dated. 除了科学c ++书籍之外,你已经拥有了所有的资源,这本书真的只是原始论文(无论如何都是这个主题)而且已经过时了。 You could look at C++ Template Metaprogramming for more modern techniques built from the expression templates ideas, but something "simple" is not going to be readily available until it IS simple. 您可以查看C ++ Template Metaprogramming,了解更多基于表达式模板构思的现代技术,但“简单”之类的东西在它很简单之前不会随时可用。

I suggest reviewing the Boost Operators at Boost Operators - Arithmetic . 我建议在Boost Operators中查看Boost算子 - 算术 These are templated methods that extend fundamental arithmetic and comparison operations. 这些是模板化的方法,扩展了基本的算术和比较操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM