[Issue 4381] New: Length attribute for std.typecons.Tuple
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 24 04:01:16 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4381
Summary: Length attribute for std.typecons.Tuple
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-06-24 04:01:13 PDT ---
This little program (that doesn't work with DMD v2.047) shows why a (constant)
length attribute can be quite useful for tuples:
import std.typecons: Tuple;
import std.typetuple: TypeTuple;
template Iota(int start, int stop) { // 2 argument version
static if (stop <= start)
alias TypeTuple!() Iota;
else
alias TypeTuple!(Iota!(start, stop-1), stop-1) Iota;
}
void main() {
alias Tuple!(char, int, int) Unit;
auto u1 = Unit('x', 1, 2);
auto u2 = Unit('y', 10, 20);
foreach (i; Iota!(1, Unit.length))
u1.field[i] += u2.field[i];
}
In that program u1.length (and maybe Unit.length too) needs to be 3.
--
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