From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2020-01-24 08:44:52
> 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.
template<typename T, size_t N>
using heap_static_array = std::unique_ptr<std::array<T, N>>;
Yeah I know the interface won't be exactly the same. But I don't agree
with "have the optimization applied". It is more than an optimization,
its more like a separate type...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk