正如我知道如何将模板函数作为模板参数传递一样,我现在正努力以类似的方式传递变量模板。
这是我尝试过的最小示例:
#define PASS_VARIABLE_TEMPLATE(name) [dummy=nullptr](auto&&...args) \
{return name<decltype(args)...>;}
//testing
template <typename T>
bool value = std::is_fundamental<T>::value;
template <typename Hax>
void print_bool(Hax h)
{
std::cout << h(int{}) << std::endl; // no error, wrong output
//std::cout << h(int{}, float{}) << std::endl; // error, good
}
int main()
{
print_bool(PASS_VARIABLE_TEMPLATE(value)); //prints 0 instead of 1
}
如果它编译,那么为什么输出是错误的?