So the way you use my function is like this:
|
cout << GCD<12,6>::value << endl;
|
That instantiates the first template with A == 12 and B == 6.
The enum inside that template instance recursively instantiates
GCD<A,B> again, this time with A = 6 and B = 0.
But I've specialized the GCD template for all cases where B == 0, so
this time the second template is instantiated with A == 6. This instantiation
sets value = A, or 6 in this case.
So GCD<12,6>::value == GCD<6,0>::value == 6.
Hint: Note the use of the word "recursively" above. You'll also note
that Euclid's algorithm is recursive.
The webpage I referenced all but gives you the C++ code to implement GCD.