| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
---- |
| 4 |
instantiated:long |
| 5 |
instantiated:int |
| 6 |
---- |
| 7 |
*/ |
| 8 |
struct S { |
| 9 |
static int foo(T)(int i) { pragma(msg, "instantiated:", T.stringof); return 0; } |
| 10 |
static int foo(T)(string s) { return 1; } |
| 11 |
} |
| 12 |
|
| 13 |
alias foo0 = __traits(getOverloads, S, "foo", true)[0]; |
| 14 |
alias bar0 = foo0!long; // prints "instantiated:long" |
| 15 |
enum x = S.foo!long(0); // should not print "instantiated:long" again. |
| 16 |
static assert(bar0(3) == 0); |
| 17 |
alias bar0int = foo0!int; // prints "instantiated:int" |
| 18 |
enum y = S.foo!int(0); // should not print "instantiated:int" again. |
| 19 |
static assert(!__traits(compiles, bar0("hi"))); |
| 20 |
|
| 21 |
alias foo1 = __traits(getOverloads, S, "foo", true)[1]; |
| 22 |
alias bar1 = foo1!long; |
| 23 |
static assert(bar1("hi") == 1); |
| 24 |
static assert(!__traits(compiles, bar1(3))); |