Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Building a mpl::vector from an expression
From: Eric Niebler (eric_at_[hidden])
Date: 2009-08-19 13:15:08


christophe henry wrote:
> Hi Eric,
>
> > You could use reverse_fold instead of reversing the whole list after the
> > transform. Or you could use reverse_fold_tree to get the vector and then
> > pop the attribute_ off the front. That's probably fastest and simplest.
>
> I must be doing something wrong (I suppose it has something to do with
> my second "when") because parsing:
> attributes_ << int() << bool() << string()
>
> With the above given grammar gives me a mpl::vector<string,bool,int>,
> which is normal, but if I simply and naively replace fold by
> reverse_fold, all I get is a mpl::vector<int>.
>
> Am I missing something obvious?

Please see below:

   #include <string>
   #include <boost/mpl/vector.hpp>
   #include <boost/mpl/push_back.hpp>
   #include <boost/mpl/pop_front.hpp>
   #include <boost/proto/core.hpp>
   #include <boost/proto/transform.hpp>
   namespace proto = boost::proto;
   namespace mpl = boost::mpl;
   using proto::_;

   namespace My
   {
     struct my_tag {};

     template<class X = proto::is_proto_expr>
     struct attribute_
     {
       BOOST_PROTO_BASIC_EXTENDS(
           proto::terminal<my_tag>::type
         , attribute_
         , proto::default_domain
       )
     };

     attribute_<> const attribute = {{}};

     struct BuildAttributes
       : proto::make<
           mpl::pop_front<
             proto::fold_tree<
                 _
               , mpl::vector0<>()
               , mpl::push_back<proto::_state, proto::_value>()
>
>
>
     {};
   }

   int main()
   {
     mpl::vector3<int, std::string, bool> x =
       My::BuildAttributes()(
         My::attribute << int() << std::string() << bool()
       );
   }

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