Created
May 10, 2019 17:02
-
-
Save alexguirre/4e25baecf869a23395fc6894f7abefd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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