Suppose I implement a constant-length data structure comparable to a dynamic array. Ie, I give the data structure the length lin the constructor. Then this instance of the data structure can never contain more elements than l. I want the data structure to have an interface that is as close as possible to the STL.
How do I implement a method max_sizefor this class? Should there be a reference design lin the constructor? Or should it be std::numeric_limits<size_type>::max()?
The documentation for this method states:
Returns the maximum number of elements that a container can hold due to system or library limitations, i.e. std :: distance (begin (), end ()) for the largest container.
This documentation is read as if it were for the largest container, so this should be the last definition. However, this method is a non-static method that hints that it should return information about the current instance of the data structure, rather than a general limit on how a large other instance of this data structure can get.
So what is the desired semantics max_size? Max of this instance or max of the hypothetical "largest" instance?
source
share