boost-proto

Transforming a Boost C++ Phoenix Expression Tree

99封情书 提交于 2020-01-02 04:40:09
问题 In the Boost Phoenix article, "Transforming the Expression Tree", here, a set of specialisations of a custom invert_actions class, are used to invert binary arithmetic expressions. For example a+b becomes a-b ; a*b becomes a/b ; and vice versa for both. This involves a recursive traversal of the expression tree - however, this traversal stops when an expression involving an operator not explicitly handled is encountered. For example, _1+_2-_3 will become _1-_2+_3 , but _1+_1&_2 will stay as

How to parse DSL input to high performance expression template

廉价感情. 提交于 2019-12-22 00:07:02
问题 ( EDITED both title and main text and created a spin-off question that arose) For our application it would be ideal to parse a simple DSL of logical expressions. However the way I'd like to do this is to parse (at runtime) the input text which gives the expressions into some lazily evaluated structure (an expression template) which can then be later used within more performance sensitive code. Ideally the evaluation is as fast as possible using this technique as it will be used a large number

Static functions from boost.lambda or boost.phoenix

荒凉一梦 提交于 2019-12-19 16:47:32
问题 I regularly use boost.lambda (and phoenix) to define lambda functions in C++. I really like their polymorphic property, the simplicity of their representation and the way they make functional programming in C++ so much easier. In some cases, it's even cleaner and more readable (if you're used to reading them) to use them for defining small functions and naming them in the static scope. The way to store these functionals that resembles conventional functions the most is to capture them in a

Subscript operator[] error with Boost C++ Phoenix user-defined argument

女生的网名这么多〃 提交于 2019-12-10 19:56:59
问题 With an existing Boost Phoenix (placeholder) argument, such as _1 , I can use the array/subscript operator. For example, the following excerpt will display a 1 . int arr[4] = {1,2,3,4}; std::cout << _1[0](arr) << std::endl; However, if I define my own placeholder argument: phoenix::actor<phoenix::expression::argument<1>::type> const my_1 = {{}}; though it works fine unadorned (the following outputs a 7): std::cout << my_1(7) << std::endl; if I attempt to use the subscript operator (as above):

boost.proto + detect invalid terminal before building the expression tree

淺唱寂寞╮ 提交于 2019-12-07 10:40:54
问题 I was playing with Boost.Proto, mostly for fun and to see if in future I could make some use of it in my own projects. That said, as probably most beginners of this library, i've played with a modified version of the 'lazy vector' example, but using transforms instead of contexts to perform the evaluation. The vector is defined as follows (ok, i know, 'vector' is not a good name for something defined at the global namespace scope...) template <std::size_t D, class T> class vector { T data_[D]

boost.proto + modify expression tree in place

一个人想着一个人 提交于 2019-12-06 03:53:31
问题 Background question: boost.proto + detect invalid terminal before building the expression tree. Hi, what i'm trying to achieve is create a copy of an expression tree, where all vectors are substituted with their begin iterators (in my case is a raw pointer) increment the iterators in place dereference iterators in the tree, but that part should be relatively easy. So, for 1. I ended up with this code /////////////////////////////////////////////////////////////////////////////// // A

boost.proto + detect invalid terminal before building the expression tree

ⅰ亾dé卋堺 提交于 2019-12-05 12:11:19
I was playing with Boost.Proto, mostly for fun and to see if in future I could make some use of it in my own projects. That said, as probably most beginners of this library, i've played with a modified version of the 'lazy vector' example, but using transforms instead of contexts to perform the evaluation. The vector is defined as follows (ok, i know, 'vector' is not a good name for something defined at the global namespace scope...) template <std::size_t D, class T> class vector { T data_[D]; enum { dimension = D }; // Constructors, destructors... }; // expression wrapper template <class>

Transforming a Boost C++ Phoenix Expression Tree

那年仲夏 提交于 2019-12-05 09:38:09
In the Boost Phoenix article, "Transforming the Expression Tree", here , a set of specialisations of a custom invert_actions class, are used to invert binary arithmetic expressions. For example a+b becomes a-b ; a*b becomes a/b ; and vice versa for both. This involves a recursive traversal of the expression tree - however, this traversal stops when an expression involving an operator not explicitly handled is encountered. For example, _1+_2-_3 will become _1-_2+_3 , but _1+_1&_2 will stay as it is (there is no handler for & ). let(_a = 1, _b = 2) [ _a+_b ] will also be left unchanged. I had

How to parse DSL input to high performance expression template

扶醉桌前 提交于 2019-12-04 21:34:24
( EDITED both title and main text and created a spin-off question that arose) For our application it would be ideal to parse a simple DSL of logical expressions. However the way I'd like to do this is to parse (at runtime) the input text which gives the expressions into some lazily evaluated structure (an expression template) which can then be later used within more performance sensitive code. Ideally the evaluation is as fast as possible using this technique as it will be used a large number of times with different values substituting into the placeholders each time. I'm not expecting the

boost.proto + modify expression tree in place

牧云@^-^@ 提交于 2019-12-04 10:04:41
Background question: boost.proto + detect invalid terminal before building the expression tree . Hi, what i'm trying to achieve is create a copy of an expression tree, where all vectors are substituted with their begin iterators (in my case is a raw pointer) increment the iterators in place dereference iterators in the tree, but that part should be relatively easy. So, for 1. I ended up with this code /////////////////////////////////////////////////////////////////////////////// // A transform that converts all vectors nodes in a tree to iterator nodes struct vector_begin : proto::transform