Boost logo

Boost Users :

Subject: [Boost-users] [fusion] Wrapping a Fusion sequence
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2012-08-28 19:10:35


I'm looking for a way to create a Fusion sequence wrapper that is itself
a Fusion sequence and forwards all 'calls' to its wrapped sequence.
Something in the lines of

     template< typename Sequence >
     struct sequence_wrapper
     {
         explicit sequence_wrapper( Sequence const& s ) : seq( s ){}

         Sequence seq;
     };

where sequence_wrapper< Sequence > is a Fusion sequence as well, and
works just as Sequence would. The reason I need this is that I have
several functions that operate on Fusion sequences (where all elements
satisfy some special requirements), and I would like to add some syntax
sugar for which I need a custom type to add overloaded operators to. I
do not need the result of operations on a sequence_wrapper to return a
sequence_wrapper as well, only the syntax sugar related calls would
return a (manually) wrapped sequence. For instance, appending elements
to a sequence using the comma operator (somewhat of a Boost.Assign for
Fusion sequences):

     template< typename Sequence, typename T >
     sequence_wrapper<
         typename boost::fusion::result_of::push_back<
             Sequence const&
           , T
>::type
> operator,( Sequence const& seq, T const& v )
     {
         return
             sequence_wrapper<
                 typename boost::fusion::result_of::push_back<
                     Sequence const&
                   , T
>::type
>( boost::fusion::push_back( seq, v ) )
             ;
     }

What would be the best way to achieve this (if it is indeed supported by
the library)? I'm particularly trying to avoid creating a Fusion
sequence from scratch, as I would like to use whatever sequence is
returned by Fusion operations. Would inheritance + specialization of
`tag_of` to return the tag of the wrapped sequence just work? Or will I
need to define a tag of my own and implement all required functions to
just forward the call?

Thank you in advance.

Agustín K-ballo Bergé.-
http://fusionfenix.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