On 03/11/2012 09:41 PM, Manu wrote:
On 11 March 2012 20:57, Andrei Alexandrescu
...

    Regarding low-level efficiency, the main issue is that structs and
    function argument lists have distinct layouts. Consider:

    import std.stdio, std.typecons;
    int a(int b, int c) {
        return b + c;
    }
    auto foo() {
        return tuple(1, 1);
    }
    void main() {
        writeln(a(foo().expand));
    }

    An adjustment may be needed from the output of a() to the arguments
    of foo(). (Probably not in this case.) I understand that someone
    very concerned with low-level performance would scrutinize such code
    carefully.


Wow, I can't imagine how '.expand' could possibly work :) .. that looks
like total magic. A parameter list can be populated by items collected
in a tuple via a property?

The property is a built-in tuple. :)

Tuple's implementation is not a lot more complicated than this:

struct Tuple(T...){
    T expand;
    alias expand this;
}

// 'magic' already available
int a(int b, int c){
    return b+c;
}

void main(){
    auto tuple = Tuple!(int, int)(1,2);
    writeln(a(tuple.expand));
}

Reply via email to