What does the C++ standard say about what sizeof(std::array<char, N>)
should be (for some constant N
)?
In a comment to a different question, it was mentioned that std::array
is not always "stack allocated". The comment was in response to a different comment that speculated that putting a too large of a constant for std::array
that is declared as a local variable could cause the program to abort due to insufficient resources for the "stack allocated" variable. I assume the followup comment meant that it would be possible for std::array
to somehow switch to a dynamic allocation mode.
I could imagine that there could be some kind of SFINAE could be applied for an array size threshold that triggers a specialization of std::array
that actually dynamically allocates an array and manages it. In that case, the sizeof(std::array<...>)
might just be the size of a pointer. Is that allowed to happen?