Boost logo

Boost :

From: Hamish Mackenzie (boost_at_[hidden])
Date: 2001-11-27 09:14:18


On Tue, 2001-11-27 at 11:30, Peter Dimov wrote:
> The other idea I tossed around - basing type lists and tuples on std::pair -
> didn't seem to fly, either. But it, too, has some benefits. Some std::pair
> operations generalize very well to pair-based tuples - like the existing
> operator== and operator<. A 'political' argument in favor of std::pair is
> that it would provide a 'common ground' for the Loki type list manipulation
> library and Boost.Tuple.

I for one think its a good idea to use it for implementation. The only
problem is if we use it publicly rather than duplicating the interface
or using private inheritance.

This is to avoid this problem...

template< class Item1, class Item2 >
void f( std::pair< Item1, Item2 > )
{
...
}

Now if typelist item "is a" std::pair someone might (quite resonably)
write...

f( make_tuple( 1, 2 ) );

and probably get a nasty surprise at runtime rather than compile time.
This is because Item2 == std::pair< int, typelist::nil >.

For the same reason fist and second must become head and tail.
Consider...

template< class TypeList >
void f( TypeList t )
{
...
}

f( std::make_pair( 1, 2 ) );

Hamish


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk