ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
Re: [boost] Userfriendly interaction of tuples with mpl containers
by Aleksey Gurtovoy other posts by this author
Jan 15 2004 11:04AM messages near this date
[boost] Re: Userfriendly interaction of tuples with mpl containers | [boost] Re: Userfriendly interaction of tuples with mpl containers
Daniel Krügler wrote:
>  Hi boosters,

Hi Daniel,

> 
>  I am just doing first steps in using the boost::mpl library, which is
>  really great.
>  Obviously due to my ignorance of knowing it not better, I tried the
>  following:
> 
>  #include <boost/mpl/vector.hpp>
>  #include <boost/mpl/size.hpp>
>  #include <boost/mpl/void.hpp>
>  #include <boost/tuple/tuple.hpp>
> 
>  template<
>      typename T0 = boost::mpl::void_, typename T1 = boost::mpl::void_,
>      typename T2 = boost::mpl::void_, typename T3 = boost::mpl::void_,
>      typename T4 = boost::mpl::void_, typename T5 = boost::mpl::void_,
>      typename T6 = boost::mpl::void_, typename T7 = boost::mpl::void_,
>      typename T8 = boost::mpl::void_, typename T9 = boost::mpl::void_
>      >
>  class Test
>  {
>      typedef boost::mpl::vector<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
>          InternalTypeContainer;
> 
>      typedef boost::tuples::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
>  Tuples; // Fragile code!!
>      Tuples m_Tuple;
>  };
> 
>  typedef Test<double, char, bool> MyTypes;
> 
>  As you will belief, that will not compile successfully, because
>  boost::mpl::void_ is
>  an undefined type (similar to void) and I am trying to fill my tuple
>  partially with undefined
>  types. So my problem is:
> 
>  Does there exist a boost::mpl way (?) to define my
>  boost::tuples::tuple<> inside the given
>  Test class template until the last non-mpl::void_ is filled into it?
>  (Iteration until end??)

This won't give you an exact equivalent of
'boost::tuples::tuple<T0,...,T9> ',
but for many practical purposes it's close enough:

    template< typename Types >  struct tuple_gen
        : mpl::fold_backward<
              Types
            , boost::tuples::null_type
            , boost::tuples::cons<_2,_1> 
            > 
    {
    };


    template<
        typename T0 = boost::mpl::void_, typename T1 = boost::mpl::void_,
        typename T2 = boost::mpl::void_, typename T3 = boost::mpl::void_,
        typename T4 = boost::mpl::void_, typename T5 = boost::mpl::void_,
        typename T6 = boost::mpl::void_, typename T7 = boost::mpl::void_,
        typename T8 = boost::mpl::void_, typename T9 = boost::mpl::void_
        > 
    class Test
    {
        typedef mpl::vector<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>  types_;

        typedef typename tuple_gen<
              mpl::filter_view<
                  types_
                , mpl::not_< mpl::is_void_<_1>  >
                > 
            > ::type Tuples;

        Tuples m_Tuple;
    };


> 
>  Or does their exist another tuple class, which I should try to use at
>  this place?

Joel de Guzman's Fusion library (http://tinyurl.com/yvxzm) has the one that
is about to replace the current implementation, and much more. In general,
Fusion is definitely a must use tool if you are doing anything more than a
very basic metaprogramming with tuples.

HTH,
--
Aleksey Gurtovoy
MetaCommunications Engineering
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Daniel =?iso-8859-1?Q?Kr=FCgler?= (nee Spangenberg)
Daniel =?iso-8859-1?Q?Kr=FCgler?= (nee Spangenberg)
Aleksey Gurtovoy
Giovanni Bajo

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved