When using a template with multiple functions within it, is it possible to access the underlying functions directly? Not sure I am missing anything, but what works when the functions are named differently from the headline template doesn't work when the functions are named the same.

import std.stdio: writeln;
import std.traits: isFunction;

template foo(T) {
    void foo(U)(U x) {
        writeln("here0");
    }

    void foo(U, V)(U x, V y) {
        writeln("there0");
    }
}

template bar(T) {
    void baz(U)(U x) {
        writeln("here1");
    }

    void baz(U, V)(U x, V y) {
        writeln("there1");
    }
}

void foobar(T)(T x) {}

void main() {
foo!int.foo!(float, double)(1f, 2.0); //Error: template foo(U)(U x) does not have property foo writeln(isFunction!(foo!int)); //prints false, as expected b/c not smart enough to look through writeln(isFunction!(foo!int.foo!float)); //Error: template identifier foo is not a member of template onlineapp.foo!int.foo(U)(U x)
    writeln(isFunction!(foo!int.foo!(float, double))); //ditto

    bar!int.baz!(float, double)(1f, 2.0); //prints there1
writeln(isFunction!(bar!int.baz!(float, double))); //prints true

    writeln(isFunction!(foobar!int)); //prints true
}


Reply via email to