Checking the size of a tr1 array at compile time

475 views Asked by At

I just found out that boost::array::static_size isn't part of tr1::array, or at least it's not in my implementation (GCC 4.2.1) and I can't find it in any tr1 documentation.

Is there another way to perform a compile-time assertion on the number of elements in a tr1 array?

e.g. The following works with a boost array but not a tr1 array:

template<typename T>
void CheckArray(const T& input) {
  BOOST_STATIC_ASSERT(T::static_size >= 2);
}

I know I can just use boost's array instead, but I'm curious.

If there's no way to do it, maybe someone knows why static_size wasn't included in tr1? Is it just a feature that was added to boost after tr1 was created?

1

There are 1 answers

0
Jeremiah Willcock On BEST ANSWER

TR1 itself says that std::tuple_size<array<T, N> >::value returns N, the size of the array.