Boost logo

Boost :

From: Persson Jonas (jonas.persson_at_[hidden])
Date: 2003-11-03 04:26:29


> -----Original Message-----
> From: Eric Friedman [mailto:ebf_at_[hidden]]
> Sent: den 31 oktober 2003 22:31
> To: boost_at_[hidden]
> Subject: [boost] Re: Variant size bug?
>
>
> David Abrahams wrote:
> > Brian McNamara <lorgon_at_[hidden]> writes:
> >
> >
> >>On Thu, Oct 30, 2003 at 02:18:11PM -1000, David Abrahams wrote:
> >>
> >>>Persson Jonas <jonas.persson_at_[hidden]> writes:
> >>>
> >>>>int main() {
> >>>> typedef boost::variant<> Var0;
> >>>> int s0 = boost::mpl::size<Var0::types>::type::value;
> >>
> >>...
> >>
> >>>>}
> >>>>
> >>>>>From this I expected the output:
> >>>>0,1,2,3
> >>>>
> >>>>but I got:
> >>>>1,1,2,3
> >>>
> >>>Well that's about as good as anyone could want, since there are no
> >>>zero-sized types.
> >>
> >>Looking closely, I don't think this is the issue.
> >>The number he is printing is the compile-time-constant
> >>length-of-list-of-types, and not the sizeof() any object, right?
> >
> >
> > Oh, right.
> >
> >
> >>You can have a zero-length MPL sequence, yes?
> >
> >
> > Yep.
> >
> > 's a bug.
> >
>
> 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?

        / Jonas


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