Reputation: 42297
#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()
{}
I know the error is due to the compiler takes the "greater than" sign '>' as a template termination sign.
My question is: In such a case, how to make the comparison expression legal?
Upvotes: 6
Views: 183
Reputation: 62975
Put the expression in parenthesis:
#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() { }
Upvotes: 8