Skip to content

Instantly share code, notes, and snippets.

@ShaderManager
Last active April 7, 2016 17:29
Show Gist options
  • Save ShaderManager/88f43579b238ab945bcd4c7ce3bb17f2 to your computer and use it in GitHub Desktop.
Save ShaderManager/88f43579b238ab945bcd4c7ce3bb17f2 to your computer and use it in GitHub Desktop.
#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