There is the BOOST_BINARY
macro. used like this
int array[BOOST_BINARY(1010)];
// equivalent to int array[012]; (decimal 10)
To go with your example:
template<int N> struct binary { static int const value = N; };
binary<BOOST_BINARY(10101)> a;
Once some compiler supports C++0x's user defined literals, you could write
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];