I am trying to understand patterns and patterns of variables. Consider this:
template<int M, int N>
const int gcd1 = gcd1<N, M % N>;
template<int M>
const int gcd1<M, 0> = M;
std::cout << gcd1<9, 6> << "\n";
He prints 0, which is wrong. However, if I use constexprinstead of the constabove, I get the correct answer 3. I get the correct answer again with the structure template:
template<int M, int N>
struct gcd2 {
static const int value = gcd2<N, M % N>::value;
};
template<int M>
struct gcd2<M, 0> {
static const int value = M;
};
std::cout << gcd2<9, 6>::value << "\n";
What am I doing wrong?
Edit:
gcd1Also compiles fine without specialization in the base package. How so? I am using Visual Studio 2015.
source
share