Storage is a variable-size container whose elements are arranged in a strict linear order.
Storage extends the Container concept with some Sequence-like functionality. The main difference with the Sequence concept however is that the Storage concept does not require default-initialisation of its elements.
X | A type that is model of Storage |
T | The value_type of X |
t | An object of type T |
n | object of type convertible to X::size_type |
Name | Expression | Type requirements | Return type |
---|---|---|---|
Size constructor | X(n) | T is DefaultConstructible | X |
Fill constructor | X(n,t) | X | |
Range constructor | X(i, j) | i and j are Input Iterators whose value type is convertible to T | X |
Resize | a.resize(n, t) | a is mutable | void |
Resize | a.resize(n) | a is mutable | void |
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Default-constructor | X() | Creates 0 elements. | size()==0 | |
Size-constructor | X(n) | n>=0 | Creates n elements. Elements are constructed without an initializer. That is if T is a (possibly cv-qualified) non-POD class type (or array thereof), the object is default initialized. Otherwise, the object created has indeterminate value. See the sentance "If new initializer is omitted" in section 5.3.4 paragraph 15 of the ISO C++ standard. | size()==n |
Fill-constructor | X(n,t) | n>=0 | Creates n initialised element with copies of t |
size()==n |
Range constructor | X(i, j) | [i,j) is a valid range. | copies the range [i,j) to the storage | size() is equal to the distance from i to j. Each element is a copy of the corresponding element in the range [i,j). |
Resize | a.resize(n, t) | n <= a.max_size() | Modified the container so that it has exactly n elements. The container may be reallocated if its size changes. Existing element values are preserved, additional elements are copies of t . |
a.size() == n |
Resize | a.resize(n) | n <= a.max_size() | Modified the container so that it has exactly n elements. The container may be reallocated if its size changes. Element values are undefined. That is each element value may be a previously assigned value or the value when it was constructed. |
a.size() == n |