Reputation: 69
Not quite the same as Stack-Overflow Question: Constant Size Vector.
I need a container for size_t with the following properties:
The array class doesn't do the trick because array always contains the given number of elements. So I need a container that distinguishes between the memory it reserves and the items that it actually contains yet.
Who knows a suitable container in the c++2020 standard?
Upvotes: 2
Views: 142
Reputation: 11410
The definition of vector is:
template<class T, class Allocator = std::allocator<T>> class vector;
https://en.cppreference.com/w/cpp/container/vector
Notice the Allocator
part. :-)
So, if you were, say, in a high-code-maturity environment with a linter that forbids the use of new
, you could provide an allocator that allocates from a fixed static pool. This allocator could enforce the needed constraints.
Upvotes: 2