Querying Function Template Restrictions

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 9 04:57:11 PDT 2016


In what ways can I compile-time introspect the template 
restrictions of a specific function overload set in D?

In other words if I have, for instance,

T f(T)(T x) if (isFloat!T) {}
T f(T)(T x) if (isInteger!T) {}

T g(T)(T x) if (isFloat!T && isInteger!T) {}

can I somehow at compile-time query that

- f() is a function having *two* overloads where the first takes 
an integer and the second takes a float?
- g() is a function having *one* overload taking either an 
integer or a float?

Or is it only via trial-and-error calls such as

__traits(compiles, { f(1); } ); // ok
__traits(compiles, { f(1.2); } ); // ok
__traits(compiles, { f("1"); } ); // not ok
__traits(compiles, { f('1'); } ); // not ok

__traits(compiles, { g(1); } ); // ok
__traits(compiles, { g(1.2); } ); // ok
__traits(compiles, { g("1"); } ); // not ok
__traits(compiles, { g('1'); } ); // not ok

I can get that information?


More information about the Digitalmars-d-learn mailing list