Narek Narek - 1 month ago 19
C++ Question

STL container sizeof reqirement

Is there any requirement on STL container

sizeof
s? For example I could implement
std::list
using
Node
as follows:

struct Node
{
Node* left;
Node* right;
T value;
};


and store two pointer or object of Node such as:

Node* m_head;
Node* m_tail;


or

Node m_head;
Node m_tail;


Considering that value type
T
can be massive, the
sizeof
of
list
can be very large. Is it acceptable?

Answer

No there is no requirement in the standard of what the size of the container should be. What the standard details is what the behavior of the data structure is. It also details the complexity of the operations done to it and of its member functions. This in turn may limit how you design it in order to conform to those requirements but if you can figure out how to maintain those requirements in a different way the standard allows that.

Comments