I was having fun with attempts to pass function template as template template
argument. Of course C++ doesn't allow passing function templates this way. But I came up with simple hax:
#include <iostream>
#define PASS_TEMPLATE(name) [](auto&... args){return name(args...);}
template <typename T, typename S>
void function_template(T t, S s) {std::cout << t << ' ' << s << std::endl;}
template <typename Hax, typename T, typename S>
auto test(Hax hax, T t, S s)
{
return hax(t, s);
}
int main()
{
test(PASS_TEMPLATE(function_template), 1, 1.5);
}
Demo
The question is:
- Is this viable approach? (Is it safe? No corner cases?)
- Is it universal, or are there cases that will cause compilation to fail?
- Are there other alternatives to achieve this? (I know some people don't like macros)
I was testing this only on GCC 6.1.0 (I really hope it's not GCC extension or something)