expression-templates

Expression templates and C++11

你离开我真会死。 提交于 2019-11-27 09:07:51
问题 Let's look at one particular benefit of expression templates: ETs can be used to avoid vector-sized temporaries in memory which occur in overloaded operators like: template<typename T> std::vector<T> operator+(const std::vector<T>& a, const std::vector<T>& b) { std::vector<T> tmp; // vector-sized temporary for_each(...); return tmp; } In C++11 the return statement of this function applies move semantics. No copy of the vector. That's a win. However, if I look at a simple expression like d = a