A Container is an object used to store other objects and taking care of the management of the memory used by the objects it contains.
[edit] RequirementsGiven the following types and values:
Type DefinitionT
an object type C
a container class containing objects of type T
Value Definition u, v values of type C
or const C mv a value of type C
cv a value of type const C lhs, rhs lvalues of type C
i, j values of type C::iterator
or const C::iterator
C
satisfies the requirements of Container if the following types, statements, and expressions are well-formed and have the specified semantics:
T
T
is CopyConstructible(until C++11)Erasable from C
(since C++11). typename C::reference T&
No explicit requirement typename C::const_reference const T& typename C::iterator an iterator type
C::iterator
is a LegacyForwardIterator, and its value type is T
.C::iterator
is convertible to C::const_iterator
.C::const_iterator
is a LegacyForwardIterator, and its value type is T
. typename C::difference_type a signed integer type C::difference_type
is the same as the difference type of C::iterator
and C::const_iterator
. typename C::size_type an unsigned integer type C::size_type
is large enough to represent all non-negative values of C::difference_type
. [edit] Statements Statement Semantics Complexity C c;
C c = C();
Postcondition c.empty() is true. constant C c(v);C c = C(v);
PreconditionIf v is not an rvalue of type C
, T
is CopyInsertable into C
.
C
, and C
is not a specialization of std::array or std::inplace_vector, the complexity is constant.C
Postcondition C().empty() is true. constant C(v) C
Precondition
If v is not an rvalue of type C
, T
is CopyInsertable into C
.
C&
Postcondition
C::iterator
Effect Returns an iterator pointing to the first element of mv. constant cv.begin() C::const_iterator
Effect Returns an iterator pointing to the first element of cv. constant mv.end() C::iterator
Effect Returns the past-the-end iterator of mv. constant cv.end() C::const_iterator
Effect Returns the past-the-end iterator of cv. constant v.cbegin()
C::const_iterator
Effect Returns const_cast<const C&>(v).begin(). constant v.cend()
C::const_iterator
Effect Returns const_cast<const C&>(v).end(). constant i <=> j
C::iterator
satisfies the random access iterator requirements. constant u == v bool Effect Returns u.size() == v.size() &&swap(lhs, rhs)
void Effect Exchanges the contents of lhs and rhs. constant[3] v.size()C::size_type
Effect Returns the number of elements[4] of v. constant v.max_size() C::size_type
Effect Returns the number of elements of the largest possible container of type C
. constant v.empty() bool Effect Returns v.begin() == v.end(). constant Optional container requirements
<C::value_type> Precondition Either T
models three_way_comparable
, or operator< is a total ordering relationship defined for values of type T
and const T. linear Effect Returns std::lexicographical_compare_three_way
(u.begin(), u.end(),
v.begin(), v.end(),
synth-three-way )[5]. Notes
C
, and C
is a specialization of std::array or std::inplace_vector, the complexity is linear.C
is a specialization of std::array or std::inplace_vector, the complexity is linear.In the expressions i == j, i != j, i < j, i <= j, i >= j, i > j and i - j, if i and/or j are replaced by iterators of type C::const_iterator
pointing to the same element respectively, the semantics remain the same.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 179 C++98iterator
and const_iterator
types might be incomparable required to be comparable LWG 276 C++98 T
was required to be CopyAssignable T
is required to be
iterator
and const_iterator
were not specified specified as T
LWG 774 C++98 there was no requirement on swap(a, b) added LWG 883 C++98 a.swap(b) was defined as swap(a, b),
iterator
and const_iterator
reference
and
const_reference
were poorly specified improved wording LWG 2257 C++98 two containers required linear time to compare
C::value_type
was required to be Destructible required to be Erasable from C
[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4