|
Boost : |
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-07-30 21:36:29
Reading boost::variant's documentation:
"If any bounded type is nothrow default-constructible (as indicated by
boost::has_nothrow_constructor), the library guarantees variant will
use only single storage and in-place construction for every bounded
type in the variant. Note, however, that in the event of assignment
failure, an unspecified nothrow default-constructible bounded type
will be default-constructed in the left-hand side operand so as to
preserve the never-empty guarantee."
Do I read correctly that in an attempt to assign one variant object to
another, the left-hand object _might_ silently change its type?
This makes it very difficult for the user to enforce some useful
invariants for types that have boost::variant members, which in my
mind is very important.
Wouldn't it be better to guarantee that operator= either succeeds or
doesn't change the observable state of the left-hand side operand,
even at the cost of memory allocation? In that case the other behavior
may still be provided through a separate function.
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk