SizeConstructible concept
Description
Vector and matrix objects are charactized by their size. Sometimes
it is necessary to create a vector or matrix of the same size (or
more mathematically: in the same vector-space) as another vector or
matrix. Being able to do this is exactly the purpose of the
SizeContructible concept.
Refinement of
Associated types
size_type |
The size type of the object that allows to construct another
object of the same size. The size_type must be Assignable. |
Notation
X |
A type that is a model of SizeConstructible |
x |
Object of type X |
n |
object of type convertible to X::size_type |
Definitions
Valid expressions
Name |
Expression |
Type requirements |
Return type |
Size |
x.size() |
|
size_type |
Size constructor |
X x(n) |
|
X |
Resize [1] |
v.resize(n) |
|
void |
Expression semantics
Name |
Expression |
Precondition |
Semantics |
Postcondition |
Size |
x.size() |
|
|
|
Size constructor |
X x(n) |
|
The size-constructor is not
the same as the default fill constructor as defined in the Sequence concept.
The difference is that the size-constructor is not required to
initialise any of the elements. The reason
for this is that this initialisation generally takes linear time.
And spending this time is generally not necessary because a structure
filled with default values is not practical and thus all elements
will be seperatly assigned anyway. |
x.size()==n |
Resize [1] |
v.resize(n) |
|
Resize the vector. The resize however does not
initialise new elements nor does it garantee that the content will
be preserved [2] |
v.size()==n |
Complexity guarantees
Invariants
Notes
[1] The resize member is
added because this allows to create for instance a vector of
default-constructed vectors. After construction all inner-vector's can be resized to the desired size.
[2]Similar to the
size-constructor, the
resize member does not default-initialise the elements in the
vector. Note that the Sequence concept
however does default-initialise new elements during a resize and
thus the std::vector does too.