Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-07 19:10:47


E. Gladyshev wrote:

> --- Eric Friedman <ebf_at_[hidden]> wrote:
>
> [...]
>
>>In short, then, there's no theoretical reason to treat T1 specially, but
>>it seemed to me a good compromise. Indeed, the optimization is usable
>>even in generic contexts, e.g.:
>>
>> template <typename U1, ..., typename UN>
>> class my_class
>> {
>> variant< boost::empty, U1, ..., UN > var_;
>> };
>>
>>or if using a MPL-compatible typesequence:
>>
>> template <typename Types>
>> class my_class
>> {
>> variant<
>> typename mpl::push_front< Types, boost::empty >::type
>> > var_;
>> };
>
>
> It is not a good solution. Should my_class wrapper duplicate
> all variant interfaces?
>
> Eugene

Wait a second. Do you plan on the user providing your class: 1) a set of
types; or 2) a specific variant type (e.g., variant<int,string>)?

If your answer is the first, then I do not see any way you can avoid
"duplicating" the variant interface. How else could the user specify the
set of types?

If your answer is the second, then I do not understand your original
concern (i.e., the "unpredictability" of variant). Consider another
possibility of my_class:

   template <typename Variant>
   class my_class
   {
     Variant var_;
   };

In the context of my_class, Variant is an "unknown" variant type.
Nonetheless, objects of Variant (e.g., var_) operate according to rules
that remain the same regardless of the types bounded by the variant. In
the context of my_class, objects of Variant behave as any other
variant<...> might. In short, I don't see any unpredictability here.

Please help me understand your perspective.

Eric


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