I’m writing a custom circular buffer implementation with fixed capacity (fixed at runtime by call to constructor, no resize methods) and want it to be STL-compatible.
My goal is to make it a Random Access Container. Additionally I want it to have the specific interface of an Back Insertion Sequence, but without being a sequence (no resize and inserting/erasing at arbitrary positions, …). So it would only be an extended Random Access Container.
After reading some questions about max_size() and size(), I’m still a little confused.
My current idea:
size(): number of elements contained in buffer
max_size(): capacity of buffer (maximum number of elements it can hold)
Is this correct (conforming to standard / STL)? Or do I have to handle it like (std::)array with size() == max_size()?
The standard is quite clear on the meaning of
max_size()in C++11 Table 96:If, like
std::array, the size is a property of the container type (e.g. specified by a template parameter), then that should be the same assize(). If you can instantiate the same type with various sizes, then it should be the largest allowed size.I would follow the example of the standard containers, and have a
capacity()function to tell you the capacity.