In C++11, you could do it this way. First of all, change your primary template so that it accepts a second, dummy parameter:
template<int n, typename = void>
struct Opers
{
// ...
};
Then, write a constexpr
function that determines whether an integer is a power of 2:
constexpr bool is_power_of_two(int x)
{
return (x == 1) || ((x % 2 == 0) && is_power_of_two(x / 2));
}
Finally, use SFINAE to enable or disable the specialization based on the result of your constexpr
function:
#include <type_traits>
template<int n>
struct Opers<n, typename std::enable_if<is_power_of_two(n)>::type>
{
// ...
};