Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Accessing inner types in transform
From: Eric Niebler (eric_at_[hidden])
Date: 2008-11-02 12:06:31

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)>
       typename remove_reference<Pair>::type::first_type

   template<class Pair>
   typename Pair::first_type
   operator()(Pair const &pair) const
     return pair.first;


Eric Niebler
BoostPro Computing

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at