Entirely accurate. This is due to the interface that dynamic_array attempted to emulate which was std::vector and std::array. I'm not sure of a clean way of folding in this kind of storage optimization or what the general interface would look like.
People naturally type out std::vector<int> so dynamic_array attempts to look similarly. We could maybe try something like adding a non-type template parameter representing the Extent where -1 is "dynamic" and the size must be stored and all positive values have the optimization applied.
Currently there is:
- Heap storage, resizable: vector
- Stack storage, resizable: static_vector
- Heap storage, fixed size at runtime: dynamic_array
- Stack storage, fixed size at compiletime: array
- Heap storage, fixed size at compiletime: unique_ptr<array>
Why complicate a new type with this "have the size a template param"
stuff when there already is a solution?
Usually you want this at an interface: Give me a "buffer" of data which
I can change but am not allowed to resize, but as a value type
(otherwise there is span)
The problem with the template param: You'll have to fix the size at
interface design which may not be what you want. And there already is a
type for that.
Bonus points:
template