|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2004-01-15 06:04:46
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk