Is the following a valid C++ code, and why not?
std::array<std::string, 42> a1;
std::array<int, a1.size()> a2;
It doesn't compile in GCC 4.8 (in C++11 mode). There is a simple but inelegant workaround:
std::array<std::string, 42> a1;
std::array<int, sizeof(a1)/sizeof(a1[0])> a2;
So clearly the compiler can figure out the number of elements in std::array. Why std::array::size() is not a constexpr static
function?
EDIT: I have found another workaround:
std::array<std::string, 42> a1;
std::array<int, std::tuple_size<decltype(a1)>::value> a2;