expression-templates

Constructing a qi::rule with a function attribute

非 Y 不嫁゛ 提交于 2019-12-08 02:09:05
问题 I'm trying to create a rule that returns a function<char(char const *)> constructed by currying a Phoenix expression. E.g., start = int_[_val = xxx]; rule<Iterator, function<char(char const *)> start; What should xxx be so that parsing the string "5" should give me a function that gives me the fifth character of its input? I've tried things like lambda(_a = arg1)[arg1[_a]](_1) might work, but I've not been able to hit on the magic formula. In other words, I'd like the attribute to curry arg2

Prevent expression templates binding to rvalue references

老子叫甜甜 提交于 2019-12-04 02:54:29
I understand that doing something like the following: auto&& x = Matrix1() + Matrix2() + Matrix3(); std::cout << x(2,3) << std::endl; Will cause a silent runtime error if the matrix operations use expression templates (such as boost::ublas ). Is there any way of designing expression templates to prevent the compiler from compiling such code that may result in the use of expired temporaries at runtime? (I've attempted unsuccessfully to work around this issue, the attempt is here ) Is there any way of designing expression templates to prevent the compiler from compiling such code that may result

Tutorials and Introductions to C++ Expression Templates

断了今生、忘了曾经 提交于 2019-12-03 06:13:41
问题 What are good introductions to the creation of C++ expression template systems? 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. It is mentioned in Lecture 6 of a course on Modern C++, referring back to Josuttis.The POOMA

CRTP: Compiler dependent issue with Expression Template

倾然丶 夕夏残阳落幕 提交于 2019-12-01 12:55:51
I incurred in a compiler dependent issue with the following code (stored in crtp.cc): #include <vector> #include <cassert> #include <iostream> template < class Derived > class AlgebraicVectorExpression { public: typedef std::vector<double>::size_type SizeType; typedef std::vector<double>::value_type ValueType; typedef std::vector<double>::reference ReferenceType; SizeType size() const { return static_cast<const Derived&>(*this).size(); } ValueType operator[](SizeType ii) const { return static_cast<const Derived&>(*this)[ii]; } operator Derived&() { return static_cast<Derived&>(*this); }

CRTP: Compiler dependent issue with Expression Template

走远了吗. 提交于 2019-12-01 11:57:32
问题 I incurred in a compiler dependent issue with the following code (stored in crtp.cc): #include <vector> #include <cassert> #include <iostream> template < class Derived > class AlgebraicVectorExpression { public: typedef std::vector<double>::size_type SizeType; typedef std::vector<double>::value_type ValueType; typedef std::vector<double>::reference ReferenceType; SizeType size() const { return static_cast<const Derived&>(*this).size(); } ValueType operator[](SizeType ii) const { return static

How to integrate a library that uses expression templates?

霸气de小男生 提交于 2019-11-30 11:19:40
I would like to use the Eigen matrix library as the linear algebra engine in my program. Eigen uses expression templates to implement lazy evaluation and to simplify loops and calculations. For example: #include<Eigen/Core> int main() { int size = 40; // VectorXf is a vector of floats, with dynamic size. Eigen::VectorXf u(size), v(size), w(size), z(size); u = 2*v + w + 0.2*z; } Since Eigen uses expression templates, code like u = 2*v + w + 0.2*z; In the above mentioned sample reduces to a single loop of length 10 (not 40, the floats are put into regiser by chunks of 4) without creating a

Intermediate results using expression templates

痞子三分冷 提交于 2019-11-30 08:51:24
问题 in C++ Template Metaprogramming : Concepts, Tools, and Techniques from Boost and Beyond ... One drawback of expression templates is that they tend to encourage writing large, complicated expressions, because evaluation is only delayed until the assignment operator is invoked. If a programmer wants to reuse some intermediate result without evaluating it early, she may be forced to declare a complicated type like: Expression< Expression<Array,plus,Array>, plus, Expression<Array,minus,Array> >

How to integrate a library that uses expression templates?

馋奶兔 提交于 2019-11-29 17:19:28
问题 I would like to use the Eigen matrix library as the linear algebra engine in my program. Eigen uses expression templates to implement lazy evaluation and to simplify loops and calculations. For example: #include<Eigen/Core> int main() { int size = 40; // VectorXf is a vector of floats, with dynamic size. Eigen::VectorXf u(size), v(size), w(size), z(size); u = 2*v + w + 0.2*z; } Since Eigen uses expression templates, code like u = 2*v + w + 0.2*z; In the above mentioned sample reduces to a

Intermediate results using expression templates

只愿长相守 提交于 2019-11-29 07:56:22
in C++ Template Metaprogramming : Concepts, Tools, and Techniques from Boost and Beyond ... One drawback of expression templates is that they tend to encourage writing large, complicated expressions, because evaluation is only delayed until the assignment operator is invoked. If a programmer wants to reuse some intermediate result without evaluating it early, she may be forced to declare a complicated type like: Expression< Expression<Array,plus,Array>, plus, Expression<Array,minus,Array> > intermediate = a + b + (c - d); (or worse). Notice how this type not only exactly and redundantly

Expression templates and C++11

给你一囗甜甜゛ 提交于 2019-11-28 15:18:22
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 + b + c; I see that the above function gets called twice (for both operator+ ) while the final