|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-06-24 19:26:02
On Monday 24 June 2002 06:02 pm, Eric Friedman wrote:
> Despite having received no feedback <g>, I continued to work on my
> boost::variant implementation over the weekend. The product of my labors
> is a variant that has been tested successfully with GCC 2.9.5 and MSVC
> 7.
I meant to send feedback to the first version, but time went on and it never
happened... so here's some feedback on the newer version. There are a few
points I'm concerned about:
1) Why is it that the variant can be unbounded? I'm having a hard time
justifying a variant type that contains a value that is probably one of the
specified types, but might be something else. Here's a nightmare scenario:
typedef boost::variant<int, float, string>::unbounded<true>::type MyVariant;
// ...
MyVariant v(3.14159); // think it's holding a float? nope...
Bounding the variant completely has the wonderful property that many uses of
the variant can check for completeness of decoding. So I guess there are two
questions: why do we need the ability to unbound a variant, and how would
this differ from the existing boost::any?
2) Why use the vtable idiom when the variant is completely bounded? The
vtables are quite a bit larger than the single byte needed to specify which
type of the variant is selected, and I don't see any benefit to the vtable
approach.
3) I'd really like to see the ability to construct from a type convertible to
some value that the variant can store, e.g.,
boost::variant<int, float, string> v(3.14159); // convert double to float
I'm glad to see work on a variant type. It's been discussed a million times,
but we've never had a variant type come up for review (and I've needed one
for a LONG time).
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk