Is std::array<int,10> (without myself using new) guaranteed to be allocated in the stack rather then the heap by the C++-Standard?
To be clear, I do not mean new std::array<int, 10>. I mainly wonder, if the standard library is allowed to use new inside its implementation.
I could not find more explicit answer in the standard, but
[array.overview]/2:And
[dcl.init.aggr]/1:That about covers it. No way an aggregate could allocate memory dynamically (or perhaps, do anything at all at its own during the construction). There's only an implicitly-declared trivial constructor.
Of course, if you
new std::array<...>, you get an array on "the heap".Some may be more satisfied by what we can get on cppreference:
Thirdly,
std::arraywas introduced in C++11. Why? For example, to complementstd::vectorin some ways, like usage inconstexprfunctions, where dynamic allocation is not allowed.