Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-11-03 05:05:23


Persson Jonas <jonas.persson_at_[hidden]> wrote:

>> Well, technically it's not a bug: variant<> *is*
>> variant<boost::empty>.
>>
>> I agree this may be unexpected, and so should probably be noted more
>> explicitly in the docs.
>>
>> Also, we _can_ argue whether this unexpectedness constitutes a bug in
>> variant's design. (It's certainly not an *implementation* bug though.)
>
> Well, I would argue that it is a (design) bug. It breaks the
> typelist <-> variant symmetry, and causes some of the mpl stuff to
> give the wrong result.
> Is there any reason why the user would want the interface to work
> this way?
>
> I use mpl to unroll the types in the variant, so I must have a
> termination condition. As it stands now I cannot use mpl::size or
> mpl::empty for that. How do I check at compile time if the variant
> contains any types or not?

Since modern boost libraries with a typelist interface such as tuples
and variant use MPL anyway, it would be nice to expose a typelist
typedef so that people can get the typelist and process it using MPL.
Examples:

template <typename T0, typename T1... , typename TN>
class variant
{
public:

    typedef implementation-defined typelist;

    /*...*/
};

template <typename T0, typename T1... , typename TN>
class tuple
{
public:

    typedef implementation-defined typelist;

    /*...*/
};

Another alternative is to ask MPL to open up its namespace to allow
the specialization of mpl::begin<s> and mpl::end<s>, so we can add
our own typelist-savvy classes. It wouldn't be possible, due to
potential name clashes to put the begin<s>, end<s> in the class'
namespace. For example, Fusion already has a begin(t) and end(t)
functions and it's not legal to have both a class/struct and a
function in the same namespace.

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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