[Proto] Accessing inner types in transform

Let's say I have a grammar which have the following terminal proto::terminal<std::pair<_,_>> I want to retrieve the first type of the pair in the terminal. Can I write : when< terminal< pair<_,_> >, _value::first()> or should I wrote a small meta-function that extract this type ? when< terminal< pair<_,_> >, first_(_value)> TIA -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Joel Falcou wrote:
Let's say I have a grammar which have the following terminal proto::terminal<std::pair<_,_>>
I want to retrieve the first type of the pair in the terminal. Can I write :
when< terminal< pair<_,_> >, _value::first()>
Nope, sorry.
or should I wrote a small meta-function that extract this type ?
when< terminal< pair<_,_> >, first_(_value)>
You'll have to write a callable polymorphic function object. Something like: struct first : proto::callable { template<class Sig> struct result; template<class This, class Pair> struct result<This(Pair)> { typedef typename remove_reference<Pair>::type::first_type type; }; template<class Pair> typename Pair::first_type operator()(Pair const &pair) const { return pair.first; } }; HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com

So i may have missed something. Here is the transform : struct C_base : bp::or_< bp::when< bp::terminal<std::pair<arithmetic_grammar ,arithmetic_grammar> > , first_(bp::_) > , bp::when< bp::terminal<i_value>, int()> , bp::when< arithmetic_grammar, bp::_value()> , bp::when< bp::unary_expr<bp::_,C_base>,C_base(bp::_child)> , bp::when< bp::binary_expr<bp::_ ,arithmetic_grammar ,arithmetic_grammar > , binary_result<arithmetic>(C_base(bp::_left),C_base(bp::_right) ) > > {}; here is first_ struct first_ : bp::callable { template<class Sig> struct result; template<class This, class Pair> struct result<This(Pair)> { typedef typename boost::remove_reference<Pair>::type::first_type type; }; }; Now when I try to get the C_base of a terminal, i got : erreur: no type named «proto_base_expr» in «struct std::pair<float, float> and other similar error. What did I missed ?

Discard latest mail. Error was on my side, a terminal was badly defined. sorry for the noise. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Joel Falcou a écrit :
Discard latest mail. Error was on my side, a terminal was badly defined. sorry for the noise.
Of course, I have to send this and discover 10s later that it still don't work. So the question is still open -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Joel Falcou wrote:
So i may have missed something.
Here is the transform :
struct C_base : bp::or_< bp::when< bp::terminal<std::pair<arithmetic_grammar ,arithmetic_grammar> > , first_(bp::_)
You mean first_(bp::_value) here, right?
> , bp::when< bp::terminal<i_value>, int()> , bp::when< arithmetic_grammar, bp::_value()> , bp::when< bp::unary_expr<bp::_,C_base>,C_base(bp::_child)> , bp::when< bp::binary_expr<bp::_ ,arithmetic_grammar ,arithmetic_grammar > , binary_result<arithmetic>(C_base(bp::_left),C_base(bp::_right) ) > > {};
here is first_
struct first_ : bp::callable { template<class Sig> struct result; template<class This, class Pair> struct result<This(Pair)> { typedef typename boost::remove_reference<Pair>::type::first_type type; };
You'll need to define an operator() here, or else you'll get an error if you actually use the transform for anything other than a type computation.
};
Now when I try to get the C_base of a terminal, i got : erreur: no type named «proto_base_expr» in «struct std::pair<float, float> and other similar error.
What did I missed ?
HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler a écrit :
You mean first_(bp::_value) here, right?
Ok, it's maybe time for me to add some new glasses to my amazon wishlist. This fixed that.
You'll need to define an operator() here, or else you'll get an error if you actually use the transform for anything other than a type computation.
Yup but I tend to be lazy when I don't do anything else than type computation.
participants (2)
-
Eric Niebler
-
Joel Falcou