Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-07-02 11:43:38

----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>

> In more C++-ish terms, it says that if we have two variant types V1 and
> and the set of types that V1 can hold is a subset of the types that V2
> hold, then V1 is a subtype of V2. So if we have:
> typedef variant<int, double> V1;
> typedef variant<int, double, std::string> V2;
> then V1 is a subtype of V2 (because you can use a V1 wherever a V2 is
> without breaking type safety). Then with:
> typedef variant<int> V3;
> V3 is a subtype of V1 and V2.

OK so far.

> But 'variant<int>' is just syntactic desugaring
> for 'int' (they should be equivalent, if the C++ type system would allow
> a thing).

But they're not, let's not fool ourselves. We can't fool the compiler.

> The variant implementations given thus far have gotten about as close to
> allowing variant subtyping as we can in C++. A variant can be constructed
> from any subtype, and variants can be casted to any of the value types
> may hold. We can't ask for much more from a subtyping relation.
> > > we can get to the double
> > > (base-to-derived cast). What's inside-out?
> >
> > That's much more-analogous to derived-to-base than base-to-derived. The
> > double storage exists within the Expression object, just as the Base
> > storage exists within the Derived object. That's what's inside-out.
> That's a _really_ low-level view of the semantics, where the storage
> determines the semantic view of a type. I don't think we should consider
> storage at all when looking at the semantics of a type. I can represent
> std::string's storage as a map of floating-point values if I want, but it
> doesn't change the semantics of std::string that are apparent to the

It does if the user is allowed to iterate over the element lvalues.

> > > type expression = Literal of float
> > >
> > > | Plus of expression * expression
> > > | Minus of expression * expression
> >
> > I don't have enough of a feel for ML to comment, having never used it
> > myself. Fortunately, we're discussing C++ <0.2 wink>
> >
> > > Does it hold that Plus(x, y) is-a expression?
> >
> > Which definition of Plus/expression are you using?
> >
> > -Dave
> The ML definition.

No comment, then.

not-caring-very-much-if-we-end-up-calling-it-'cast'-ly y'rs,

Boost list run by bdawes at, gregod at, cpdaniel at, john at