On 05-11-2012 00:31, evansl wrote:
http://dlang.org/phobos/std_variant.html
says:
This module implements a discriminated union type (a.k.a. tagged union,
algebraic type).
Yet, the wiki page:
http://en.wikipedia.org/wiki/Tagged_union
says:
a tag field explicitly indicates which one is in use.
and I don't see any indication of a tag field in the std_variant.html
page. Another wiki reference:
http://en.wikipedia.org/wiki/Disjoint_union
is more explicit because it pairs the tag with the value:
(x,i)
where x is the value and i is the tag.
One reason for an explicit tag is that the bounded types may contain
the same type twice. This has lead to problems in boost::variant as
evidenced by the post:
http://article.gmane.org/gmane.comp.parsers.spirit.general/17118
In addition, both variant and tuple have a common part, a metafunction
mapping from a tag to a type; hence, this same common part could be used
to implement both tuple and a tagged variant.
A variant which actually contained a tag field I think would be more
general in that it would allow duplicate types among the bounded types
just as a tuple's bounded types can contain duplicate types.
-regards,
Larry
Yes, this is a big problem with the current std.variant implementation
(among other problems such as no recursive variants....). The best
std.variant can offer right now is the 'type' property to identify
what's stored in it.
std.variant is, unfortunately, not very useful if you want the semantics
of variants in ML-style languages.
--
Alex Rønne Petersen
[email protected]
http://lycus.org