Answer the question
In order to leave comments, you need to log in
How to use patterns to check that two numbers are equal?
I tried like this:
template<typename R, typename C, typename std::enable_if<std::is_arithmetic<R>::value && std::is_arithmetic<C>::value>::type = true>
struct are_values_equal
{
constexpr static bool value = R == C;
};
template<const std::size_t R, const std::size_t C>
struct are_values_equal
{
constexpr static bool value = R == C;
};
Answer the question
In order to leave comments, you need to log in
Answering a question from the comments. You can do this:
template <int a, int b>
class A {
public:
template<bool tmp = true>
typename std::enable_if<a==b && tmp, int>::type F() {
return 1;
}
};
...
A<1,1> a;
std::cout << a.F(); // OK.
A<2,100> b;
std::cout << b.F(); // Ошибка A<2,100> не имеет метода F().
template<>
typename std::enable_if<a==b, int>::type F()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question