Talk:Expression templates
This is the talk page for discussing improvements to the Expression templates article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
This article is rated Stub-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||
|
Untitled
editThe example won't compile, see http://groups.google.com/group/comp.lang.c++/browse_frm/thread/562d5a77cf4c1f12/ed886cdc72de4649 —Preceding unsigned comment added by 85.18.188.72 (talk) 13:33, 10 January 2011 (UTC)
Try it now... JanBielawski (talk) 00:56, 26 January 2011 (UTC)
It compiles, but seg faults when used in an example. — Preceding unsigned comment added by 173.73.2.192 (talk) 01:31, 5 January 2012 (UTC)
In this code:
template <typename E>
class VecExpression { public:
...
Isn't necessary to derive VecExpression from the class E ? Like:
template <typename E>
class VecExpression : public E { public:
...
Because, in the operators, it's casting itself/this from "VecExpression<E>" to "E const&":
double operator[](size_t i) const { return static_cast<E const&>(*this)[i]; }
If it's not deriving from E, neither has a member of type E, how the compiler will convert an empty class to a E type class? I think this is the reason of the seg fault reported by other person. — Preceding unsigned comment added by 2804:7F4:3C80:BBF5:0:0:0:1 (talk) 13:48, 31 December 2016 (UTC)
- Hello, I updated the article to fix the segfault issue. It was related to the fact the VecSum was storing dangling references to temporary objects that get destroyed early on. AdelKaraSlimane (talk) 15:11, 4 March 2023 (UTC)
c++11 move semantics not a substitute
editThere is a paragraph about move semantics supplanting the need for expression templates. This is quite wrong. They are mostly unrelated optimisations. Move semantics can help prevent the copy of buffers in function returns, but they don't prevent the intermediate steps of operations that expression templates resolve. A simple example is
string a = string("hello, ") + string("how ") + string("are ") + string("you ") + string("today") + string("?");
In this concatenation example, we have 5 intermediate operations which will all have buffers allocated of different sizes (so move semantics does nothing to help). However, with expression templates, you can return a proxy type with no actual allocation, and then in the assignment actually allocate the correct size buffer once and copy over the arguments individually. Similarly, complex expressions not involving concatenation still create temporary objects of matrices and other objects that get manipulated separately, which is wasteful compared to in place evaluation on the final object. They are completely different optimizations. I am removing that section unless others can explain how it is relevant.Ex0du5 5utu7e (talk) 20:09, 8 May 2014 (UTC)
- Agreed, they are unrelated optimizations.
decltype
(talk) 10:48, 9 May 2014 (UTC)