-
-
Save asfdfdfd/3e987b87bacc26a88cfa8ae7c7314c86 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