#include #include #include #include #include using namespace boost; struct empty {}; template struct dimension0 { static A a; enum {e = sizeof(a[0])}; typedef char (¬_an_array)[sizeof(A)/e]; }; template < std::size_t d , class A > struct array_counter; template < std::size_t d_ , class A > struct legal_array_counter { typedef typename remove_bounds::type element; enum { d = d_ }; typedef typename mpl::eval_if_c< d , array_counter , mpl::identity > >::type type; }; template < std::size_t d , class A > struct array_counter { enum { legal = is_array::value }; typedef typename mpl::eval_if_c< !legal , mpl::identity , legal_array_counter >::type type; }; template struct eval0 { typedef typename T::not_an_array not_array; }; template typename eval0< typename array_counter::type >::not_array dimension(A& a); struct X { operator void*() const; double operator[](std::size_t) const; }; template struct whatis {}; int main() { typedef X xt[1][2][3][4][5]; xt a; (void)a; char a1[sizeof dimension<0>(a)] = { 0 }; // <-- char a2[sizeof dimension<1>(a)] = { 0 }; char a3[sizeof dimension<2>(a)] = { 0 }; char a4[sizeof dimension<3>(a)] = { 0 }; char a5[sizeof dimension<4>(a)] = { 0 }; #ifdef FAIL char a6[sizeof dimension<5>(a)] = { 0 }; #endif std::cout << sizeof(a1) << ", " << sizeof(a2) << ", " << sizeof(a3) << ", " << sizeof(a4) << ", " << sizeof(a5) << '\n'; return 0; }