如何在C++模板中使用比较表达式
How to use comparison expressions in C++ templates?
#include <type_traits>
template<int n>
std::enable_if_t<n == 1, int> f() {}
// OK
template<int n>
std::enable_if_t<n > 1, int> g() {}
// VS2015 : error C2988: unrecognizable template declaration/definition
int main()
{}
我知道错误是由于编译器将"大于"符号">"作为模板终止符号。
我的问题是:在这种情况下,如何使比较表达合法?
将表达式放在括号中:
#include <type_traits>
template<int n>
std::enable_if_t<(n == 1), int> f() { }
template<int n>
std::enable_if_t<(n > 1), int> g() { }
int main() { }
相关文章:
- 使用 boost::regex (c++) 比较两个正则表达式
- 符号和未签名整数表达式之间的比较,以进行循环误差
- C++编译错误(有符号和无符号整数表达式之间的比较)
- C++ 有符号和无符号整数表达式之间的比较
- C++ 斯特劳斯特鲁普的"std_lib_facilities.h"字符串结构 – 警告:无符号表达式的比较
- 指针对象使用CPP中的指针表达式进行比较
- 有符号和无符号整数表达式之间的比较
- 如何在不使用 lambda 表达式的情况下实现特定的比较器
- 消除有符号和无符号整数表达式之间比较的优雅方式
- 在文件中找到最长的行,签名和未签名的整数表达式之间的比较
- C++比较表达式错误
- C++17中的折叠表达式-比较运算符的用例
- 与表达式或变量进行比较之间的性能差异
- C 11:比较lambda表达式
- 我的 lambda 表达式进行映射键比较有什么问题?
- C++与赋值表达式的比较是右侧表达式
- 警告:有符号和无符号整数表达式之间的比较
- 条件语句在比较表达式时的基础是什么?
- 这两个比较表达式相同吗?
- 如何在C++模板中使用比较表达式