在线文档教程

Container

C++概念:容器

Container是一个用于存储其他对象并负责管理其包含的对象所使用的内存的对象。

所需

  • C集装箱类型;

  • T元素类型;

  • a,,,b类型对象C...

类型

nametypenotes
value_typeTEraseable
referenceT&
const_referenceconst T&
iteratoriterator pointing to TForwardIteratorconvertible to const_iterator
const_iteratorconst iterator pointing to TForwardIterator
difference_typesigned integermust be the same as iterator_traits::difference_type for iterator and const_iterator
size_typeunsigned integerlarge enough to represent all positive values of difference_type

方法和操作

expressionreturn typesemanticsconditionscomplexity
C()Ccreates an empty containerPost: C().empty() == trueConstant
C(a)Ccreates a copy of aPre: T must be CopyInsertablePost: a == C(a)Linear
a = bC&destroys or move-assigns all elements of a from elements of bPost: a == bLinear
(&a)->~C()voiddestroys all elements of a and frees all memoryLinear
a.begin()(const_)iteratorIterator to the first element of aConstant
a.end()(const_)iteratorIterator to one past the last element of aConstant
a.cbegin()(since C++11)const_iteratorconst_cast<const C&>(a).begin()Constant
a.cend()(since C++11)const_iteratorconst_cast<const C&>(a).end()Constant
a == bconvertible to boolstd::equal(a.begin(), a.end(), b.begin(), b.end())(since C++14)Pre: T must be EqualityComparableConstant1 if a.size() != b.size(), linear otherwise
a != bconvertible to bool!(a == b)Linear
a.swap(b)voidexchanges the values of a and bConstant2
swap(a, b)voida.swap(b)Constant2
a.size()size_typedistance(a.begin(), a.end())Constant3
a.max_size()size_typeb.size() where b is the largest possible containerConstant3
a.empty()convertible to boola.begin() == a.end()Constant

注记

对于STD总是线性的::正向[医]列表%28自C++11%29线性表示STD::数组%28,直到C++11%29不严格恒定

  • 总是线性的std::forward_list

  • %28自C++11%29线性std::array

  • %28直到C++11%29没有严格不变

Given. i and j, objects of a container's iterator type, in the expressions i == j, i != j, i < j, i <= j, i >= j, i > j, i - j, either or both may be replaced by an object of the container's const_iterator type referring to the same element with no change in semantics.(since C++14)

  • i和j,容器%27s的对象iterator类型,在表达式中i == j,,,i != j,,,i < j,,,i <= j,,,i >= j,,,i > j,,,i - j,可以用容器%27s的对象替换其中之一或两者。const_iterator类型引用相同的元素,语义不变。 %28自C++14%29容器数据竞赛见集装箱螺纹安全...其他概念丙

  • DefaultConstructible

  • CopyConstructible

  • EqualityComparable

  • Swappable

T型

  • CopyInsertable

  • EqualityComparable

  • Destructible

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cpPreference.com/w/cpp/概念性/容器