Существует макрос BOOST_BINARY
. используется как это
int array[BOOST_BINARY(1010)];
// equivalent to int array[012]; (decimal 10)
Для примера:
template<int N> struct binary { static int const value = N; };
binary<BOOST_BINARY(10101)> a;
Если какой-то компилятор поддерживает пользовательские литералы C ++ 0x, вы можете написать
template<char... digits>
struct conv2bin;
template<char high, char... digits>
struct conv2bin<high, digits...> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0') * (1 << sizeof...(digits)) +
conv2bin<digits...>::value;
};
template<char high>
struct conv2bin<high> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0');
};
template<char... digits>
constexpr int operator "" _b() {
return conv2bin<digits...>::value;
}
int array[1010_b];