Tuples

dsimcha dsimcha at yahoo.com
Fri Feb 6 11:45:14 PST 2009


I've been thinking a little about the idea of returning tuples from functions, w.r.t. Bugzilla 2628
(http://d.puremagic.com/issues/show_bug.cgi?id=2628).   Would it be feasible to solve this by making
struct[index] for any struct w/o an opIndex overload equivalent to struct.tupleof[index]?  This would be
trivial syntactic sugar, but would allow user-defined tuples in Phobos to look like a builtin tuple, be
returned from functions, etc., while changing very little under the hood.   Furthermore, for functions that
take a tuple, we could allow structs to be implicitly cast to tuples, e.g.:

struct Foo {
     uint u;
     float f;
}

void doStuff(uint myInt, float myFloat) {}

Foo foo;
doStuff(foo);  // Implicitly casts to foo.tupleof, works.



More information about the Digitalmars-d mailing list