Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-08-04 13:02:51


On 08/04/08 09:00, Mathias Gaunard wrote:
> Emil Dotchevski wrote:
>
>>>> Do I read correctly that in an attempt to assign one variant object to
>>>> another, the left-hand object _might_ silently change its type?
>>> If an exception is thrown during assignment to a boost::variant<T0, T1,
>>> ...>, and one of the Ti is nothrow default-constructible, then the
[snip]
> Then you should use tags, and not ugly hacks.
Tags? Do you mean something like:

   template<unsigned Tag, typename Type>
   struct tagged_type
   { Type a_t;
   };

   boost::variant
   < tagged_type<0,T0>
   , tagged_type<1,T1>
   ...
>

? In this way, even if T0==T1==...==Tn, the
variant would still work but I guess the tagged_type CTOR would have
to forward its CTOR args to the a_t.


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