Boost logo

Boost :

From: Hamish Mackenzie (boost_at_[hidden])
Date: 2001-07-01 21:39:16

I have not had time to have a good look at the tuple code. I had wanted to
do it over the weekend but we spent it in Bath (the City that is).

I do have a couple of questions.

Is it possible to create an empty tuple?
and is it tuple<> or tuple< nil >?

Is it possible to partially specialize a class using a tuple (or use it in
overloaded template functions for that matter)?
template< class T >
class x;

template< class A, class B >
class x< tuple< A, B > >

I think it that this will not be possible because all the default template
parameters have not been listed. The tuple class I have been using has the
same problem (though I called it a type vector as I was using it primarily as
a list of types at first).

template< class A, class B >
class x< make_tv< A, B >::result >

does not work as the compiler can not be expected to determine the
specialization of make_tv< A, B > based on the type of result (there could be
more than one answer for all it knows). However I can work around this using

template< class A, class B >
class x< tv< A, tv< B, tv0 > > >

Does tuple have an equivalent work around? Using cons? Is cons part of the
tuple public library interface or is it part of the implementation?

Personally I think we need to introduce something like prologs list system
(there's a bunch of other cool stuff in prolog that could be in C++ but this
has to be one of the most important)...

A list in prolog is really a recursive construct using '.'
| ?- display( [a,b,c] ).

Unfortunately I don't think this can be added to C++ without changing the
language (though I would love to be proved wrong :-)

I think the simplest change to the language would be to add a special class
to an appropriate namespace (say boost::dot)

template< class T >
class dot;

Dot would have no implementation so could not be instantiated at runtime but
the code
dot< a, b, c >

would be the same as

dot< a, dot< b, dot< c, nil > > >

tuple would be something like...

template< class DotList >
class tuple;

class tuple< nill >

template< class Head, class Tail >
class tuple< dot< Head, Tail > >
  Head head_;
  Tail tail_;
  // ...

The x class I used earlier could then be specialized using

template< class A, class B >
class x< tuple< dot< A, B > > >

If you wanted backwards compatibility with older compilers you would have to
class x< tuple< dot< A, dot< B, nil > > > >

Hamish Mackenzie

Boost list run by bdawes at, gregod at, cpdaniel at, john at