|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-04-29 07:33:15
Alexander Nasonov wrote:
> Alternatively, you can implement MPL conformant sequence
> tuple_sequence<Tuple>. It's not so hard as you can imagine.
It's not indeed:
template< typename Tuple > struct tuple_iterator
{
typedef mpl::forward_iterator_tag category;
typedef typename Tuple::head_type type;
typedef tuple_iterator<typename Tuple::tail_type> next;
};
// end iterator
template<> struct tuple_iterator<boost::tuples::null_type>
{
typedef mpl::forward_iterator_tag category;
};
template< typename Tuple > struct tuple_sequence
: mpl::iterator_range<
tuple_iterator<Tuple>
, tuple_iterator<boost::tuples::null_type>
>
{
};
// test
typedef boost::tuples::tuple<int,char const*,bool> t;
BOOST_STATIC_ASSERT( mpl::size< tuple_sequence<t> >::type::value == 3 );
BOOST_STATIC_ASSERT(( mpl::equal<
tuple_sequence<t>
, mpl::list<int,char const*,bool>
>::type::value ));
> (Question to MPL's authors: when it will be documented?).
How to write your own iterator is partially documented here -
http://www.boost.org/libs/mpl/doc/paper/mpl_paper.html#sequences.concepts.
And then there is a reference doc -
http://www.boost.org/libs/mpl/doc/ref/Iterators.html.
And of course, anyone is always welcome to contribute more tutorials - it's
for sure will be appreciated.
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk