import std.traits;
import std.stdio;

void func(int a, int b=2, int c=3) {
    return a+b+c;
}

void func2(Parameters!func args = ParameterDefaults!func) {
    return func(args);
}

void main() {
    writeln(func2(1));
    writeln(func2(1,1));
    writeln(func2(1,1,1));
}

So, this does not compile. I can do that with a mixin, but I would much rather not. Is there a non-Mixin method of copying not only the function's signature, but also its default values?

The second thing I thought would be simple is to refer to call a struct's member.

struct S {
    void func(int a) {
    }
}

unittest {
    alias v = S.func;

    S s;
    s.v(12); // No property v for type S
    // UFCS to the rescue!
    v(s, 12);
    // function S.func(int a) is not callable using argument types (S, int)

    // Maybe using getMember?
    __traits(getMember, S, "func")(s, 12); // Same error
    // Maybe without UFCS
    s.__traits(getMember, S, "func")(12);
    // identifier expected following ., not __traits
}

Am I missing something?

Reply via email to