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)>
   {
     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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net