|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-08-30 07:22:08
From: "Vesa Karvonen" <vesa.karvonen_at_[hidden]>
> From: "Douglas Gregor" <gregod_at_[hidden]>
> > // for this variant
> > variant<int, float, std::string> v;
> >
> > // switch-on-type
> > vswitch(v)(
> > vcase<int>(function_object_taking_the_int_value)
> > | vcase<float>(function_object_taking_the_float_value)
> > | vcase<std::string>(function_object_taking_the_string_value)
> > );
>
> I like the above syntax. The biggest problems with it, making it difficult
to
> use, are due to limitations of the core language.
vswitch(v) ((
vcase<int>(f),
vcase<float>(g)
));
;-)
> Now, assuming that 'optional' has semantics not unlike the C/C++ pointer,
then
> according to many modern programming languages and language designers,
such
> semantics should be avoided in favor of type safe semantics. Both
'optional'
> and the C/C++ pointer are not type safe. 'variant', on the other hand, is
type
> safe.
[more on optional, any, variant]
I just wanted to say that I have one more variation to offer (called
'variant', but I'll probably have to rename it once again.)
It supports subtyping polymorphism and is basically a constrained 'any'.
i.e. variant<void> is equivalent to 'any', variant<T> stores anything that
is derived from T.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk