能否请您解释一下或提供一个链接来解释: 为什么这有效:
template <int i, int j, class T>
auto to_pair(T tuple) -> decltype(std::make_pair(std::get<i>(tuple), std::get<j>(tuple)))
{
return std::make_pair(std::get<i>(tuple), std::get<j>(tuple));
}
这不是吗?
template <class T>
auto to_pair(int i, int j, T tuple) -> decltype(std::make_pair(std::get<i>(tuple), std::get<j>(tuple)))
{
return std::make_pair(std::get<i>(tuple), std::get<j>(tuple));
}
我的意思是 int 类型作为模板参数特化和 int 参数作为通用参数有什么区别?
最佳答案
I mean what is the difference between int type being template argument specialization and int argument as a common argument?
一个在编译时定义,另一个在运行时定义。
运行时值不能用作模板参数。因此,第二种情况不起作用。
关于c++ - std::get 从模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49415272/