Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-28 03:34:27


--- Eric Friedman <ebf_at_[hidden]> wrote:

> Are you referring to the following problem?
>
> T f();
>
> class my_type
> {
> T t_;
> public:
> my_type() { }
> my_type(const my_type& other)
> : t_( f() )
> {
> }
> };
>
> variant< int, my_type > v;
>
> int main()
> {
> my_type m1;
>
> my_type m2 = m1; // ok
> v = m1; // potentially undefined: does f visit v?
> }

Yes, this is what I meant.

>
> If so, then yes, I've devised a solution for that problem, but it incurs
> quite a costly run-time overhead (i.e., a backup copy of lhs content
> required even when heap backup of lhs content is not).

I thought that you had a "simple" solution
that involves just an extra pointer?
I have not given a lot of thought to this problem,
but why is it costly? Do you mean that variant
will have to allocate memory even if one of the
types has non-throw copy-constructor?

>
> A better solution, I believe, is simply to document that accessing a
> variant *during* assignment will result in undefined behavior. That way,
> unless the user really needs to do something like the above, such (IMHO,
> excessive) overhead will be avoided.

I think that documenting the special case is almost as
good as to say that variant doesn't really
provide basic guarantees?
It'll mean that variant doesn't provide
100% basic guarantees and it cannot be singular.
Seems like a bit confusing to me.
Like you have shown in the above example the variant
access may not be so obvious.
If different teams work on different chunks of
a complex code that is operating on the same "global"
(in a particular scope) data, the basic guarantees
with this *exception* won't do them any good.
I think it would be safer for them to assume that
the basic guarantees are not provided at all.

However like you said, this example
is probably excessive but it is valid.
I am kinda undecided on this issue.
It is almost like the singular variant
is back into the picture?

Eugene

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/


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