Skip to content

Instantly share code, notes, and snippets.

@alexguirre
Created May 10, 2019 17:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alexguirre/4e25baecf869a23395fc6894f7abefd8 to your computer and use it in GitHub Desktop.
template matchingOverload(alias funcSymbol, Args...)
{
private template parametersMatch(alias funcSymbol, T...)
{
import std.traits : Parameters;
enum parametersMatch = is(Parameters!funcSymbol == T);
}
static foreach(s; __traits(getOverloads, __traits(parent, funcSymbol), __traits(identifier, funcSymbol)))
{
static if (parametersMatch!(s, Args))
{
alias matchingOverload = s;
}
}
static if (is(typeof(matchingOverload) == void))
{
import std.traits : fullyQualifiedName;
static assert(0,
"No overload of '" ~ fullyQualifiedName!funcSymbol ~ "' with types " ~ Args.stringof ~ " exists");
}
}
// pragma(msg, (matchingOverload!(Test.doSomething, string)).mangleof);
// pragma(msg, (matchingOverload!(Test.doSomething, int)).mangleof);
// pragma(msg, (matchingOverload!(Test.doSomething)).mangleof);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment