Last active
April 7, 2016 17:29
-
-
Save ShaderManager/88f43579b238ab945bcd4c7ce3bb17f2 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
#include <stdio.h> | |
#include <string> | |
template<typename Arg> const char* type_to_str(); | |
template<typename...> struct VarIterator; | |
template<typename Head> struct VarIterator<Head> | |
{ | |
static std::string eval() | |
{ | |
return type_to_str<Head>(); | |
}; | |
}; | |
template<typename Head, typename... Rest> struct VarIterator<Head, Rest...> | |
{ | |
static std::string eval() | |
{ | |
return VarIterator<Head>::eval() + ";" + VarIterator<Rest...>::eval(); | |
} | |
}; | |
template<typename... Args> std::string resolve() | |
{ | |
return VarIterator<Args...>::eval(); | |
}; | |
template<> const char* type_to_str<int>() | |
{ | |
return "int"; | |
} | |
template<> const char* type_to_str<float>() | |
{ | |
return "float"; | |
} | |
template<> const char* type_to_str<void>() | |
{ | |
return "void"; | |
} | |
template<typename Result, typename... Args> std::string resolve_func_type(Result(*)(Args...)) | |
{ | |
return resolve<Result>() + " " + resolve<Args...>(); | |
} | |
void foo(int, float) | |
{ | |
} | |
int main() | |
{ | |
printf("%s\n", resolve<int, float>().c_str()); | |
printf("%s\n", resolve_func_type(foo).c_str()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment