[Issue 8962] New: std.variant.Algebraic should support duplicate types
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 5 11:50:08 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8962
Summary: std.variant.Algebraic should support duplicate types
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P3
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: sandford at jhu.edu
--- Comment #0 from Rob Jacques <sandford at jhu.edu> 2012-11-05 11:50:07 PST ---
As std.variant.Algebraic implements a bounded discriminated union, it should
allow for duplicate types. i.e.
alias Algebraic!(string,string) A;
// Construction using: this(T)(T value, size_t id)
A a0 = A("First" ,0);
A a1 = A("Second",1);
// The type's id should be assessable by an ID member function that returns
// a size_t
switch(a0.id) {
case 0:
// The first int type
break;
case 1:
// The second int type
break;
default:
break;
}
// Similar to std.typecons.Tuple, member functions following the format of _#
// should provide a streamlined way of testing the ID and retrieving
// the Algebraic's value
assert(a0._0 == "First");
// Which is equivalent to
enforce(a0.id == 0);
assert(a0.get!string == "First");
// Similar to actual unions and std.typecons.Tuple, named members should be
// supported. Assignment to named members is allowed i.e.
alias Algebraic!(int,"x", int,"y") B;
B b = B(10,0);
assert(b.id == 0);
assert(b._0 == 10);
assert(b.x == 10);
b.y = 5;
assert(b.id == 1);
assert(b._1 == 5);
assert(b.y == 5);
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list