Is the following a valid C++ code, and why not?
std::array a1;
std::array a2;
It doesn\'t compile
array
is constexpr
, but you can't use it in this way because a1
isn't a constexpr
value. Additionally, it can't be constexpr
because string
isn't a literal type.
However, you can work around this if you want, by deducing the size_t
template parameter. Example:
#include
#include
#include
using namespace std;
template
struct array_size;
template
struct array_size > {
static size_t const size = N;
};
array a1;
array::size> a2;
int main() {
cout << a2.size() << endl;
}