Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-10-07 03:38:32

E. Gladyshev wrote:

> --- Eric Friedman <ebf_at_[hidden]> wrote:
> [...]
>>To check each type Ti in variant<T1,...,TN> would add O(n) compile-time
>>complexity. To check only the first type T1 adds only O(1) complexity.
> I thought that you have to check each type anyway
> to find the largest type, isn't it true?

Yes, it's true that each type must be checked. So perhaps "complexity"
is not the correct word to use. Nonetheless, compile-time *performance*
will be hampered, as there is a difference between O(N) and O(2N) when
waiting for compilation to finish, even if they are both in theory O(N).

Further, while I perhaps understand your complaint that variant checks
only T1 for a nothrow default constructor, it would not really buy you
anything in a generic context if variant behaved similarly for any Ti
with nothrow default-construction. That is,

   template <typename U1, ..., typename UN>
   class my_class
     variant<U1, ..., UN> var_;

Unless a precondition for use of my_class is that one of its arguments
Ui must be nothrow default-constructible, you'd still be in the same
boat even if variant checked every type. That is, you would have no way
to ensure heap allocation was avoided in general.


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