Unofficial wish list status.(Nov 2008)

bearophile bearophileHUGS at lycos.com
Sat Nov 1 09:50:33 PDT 2008


ore-sama:
> KennyTM~ Wrote:
> > Right. It should be a tuple instead of an array for more generic variants.
> > I think this (x, y) = ... is just as good as [x, y] = ...
> 
> this is useless :P use structs or arrays.

With my libs you can do:

import d.all;
Record!(string, int) foo() {
    return record("hello"[], 10);
}
void main() {
    auto s_i = foo();
    putr(s_i.d0, " ", s_i.d1); // Output: hello 10
}

Or:

import d.all;
Record!(string, int) foo() {
    return record("hello"[], 10);
}
void main() {
    string s;
    int i;
    derecord(foo(), s, i);
    putr(s, " ", i);
}

In D2 the first version will become:
import d.all;
auto foo() {
    return record("hello"[], 10);
}
void main() {
    auto s_i = foo();
    putr(s_i.d0, " ", s_i.d1); // Output: hello 10
}

Those Record are structs with several handy methods, they can be joined, cmp, hashed, etc. Even if they recursively contain other kinds of generic structs (not just other Record).
With this I don't miss a built-in multiple return too much, while we wait to have it built-in.

Bye,
bearophile



More information about the Digitalmars-d mailing list