|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-10-08 15:20:11
"E. Gladyshev" <egladysh_at_[hidden]> writes:
> --- David Abrahams <dave_at_[hidden]> wrote:
> [...]
>> > typedef variant< int, my_type > v1;
>> > typedef variant< my_type, int > v2;
>> >
>> > I think that we should just realize that
>> > in the current variant, v1 and v2 have
>> > a vastly different behaviour.
>>
>> Really? What are the differences?
>
> my_type m;
>
> for( i = 0; i < 10000; ++i )
> v1 = m;
>
> for( i = 0; i < 10000; ++i )
> v2 = m;
>
> The first loop will be executed much faster
> than the second one.
Execution speed doesn't fall under what is normally termed "behavior"
when discussing C++. As you nearly pointed out a few messages ago,
O(N) == O(k * N).
> --- Another example
>
> struct my_type
> {
> my_type( const m_type& l )
> {
> throw;
> }
> };
>
> v1 = 123;
> v2 = 123;
>
> v1 = m; //exception -> v1 = garbabe
No, IIUC, v1 holds a value-initialized int in this case.
> v2 = m; //exception -> v2 = 123
>
>
>>
>> > It just goes against any conventional
>> > wisdom and intuition. People, please...
>> >
>> > I don't think that the *weak* exception
>> > safety (the way it is implement now)
>>
>> What is "weak" exception safety?
>
> According to Eric, the content *value* of a variant after an
> exception is not guaranteed at all. Only the content *type* is
> guaranteed, and for that matter it's only guaranteed to be one of
> the bounded types, not a particular one.
That's the "basic guarantee", that all invariants are preserved and
nothing else.
>> IIUC the exception guarantees are the same whether or not the
>> optimization takes effect.
>
> IMHO, these "weak" guarantees worth nothing.
Then you'd better trade in your std::vector<T>::insert, std::sort,
and most of the rest of your standard library.
Fortunately, you're wrong about the basic guarantee's worthlessness.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk