This post should really go to comp.std.c++, but since it's down
I'm posting it here instead. The new constexpr keyword from C++0x does
not allow recursive constexpr functions, because the designers could not
think of a good use case. I've just thought of one: a compile time
greatest common factor function. It could be defined recursively as:
template <class X>
inline constexpr X gcf(X a, X b)
{
return (b == 0) ? abs(a) : gcf(b, a % b);
}
This would be useful in the implementation of duration class template
proposed in N2498
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2498.html).
This class template has the form
template <class TickType,
long long TicksPerSecond,
long long SecondsPerTick>
class duration;
and it sometimes needs to compute a compile-time greatest common factor
between the TicksPerSecond template parameters of two different
instantiations.
Joe Gottman
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]