code
template<int A, bool = !(A % 5)> struct select : select<A-1> { }; template<int A> struct select<A, true> { static int const value = A; }; template<> struct select<0, true> { static int const value = 0; }; int main() { std::cout << select<1>::value;
Save the divisor variable
template<int A, int D, bool = !(A % D)> struct select : select<A-1, D> { }; template<int A, int D> struct select<A, D, true> { static int const value = A; }; template<int D> struct select<0, D, true> { static int const value = 0; }; int main() { std::cout << select<1, 3>::value;
source share