Пространства имён
Варианты
Действия

Концепции C++: Container

Материал из cppreference.com
< cpp‎ | concept

 
 
 
Container это объект, используемый для хранения других объектов и заботе руководства памяти, используемых в нем объектов.
Оригинал:
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.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

Содержание

[править] Требования

  • C контейнерного типа
    Оригинал:
    C Container type
    Текст был переведён автоматически используя Переводчик Google.
    Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
  • T тип элемента
    Оригинал:
    T Element type
    Текст был переведён автоматически используя Переводчик Google.
    Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
  • a, b Объекты типа C
    Оригинал:
    a, b Objects of type C
    Текст был переведён автоматически используя Переводчик Google.
    Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

[править] Типы

name type notes
value_type T Destructible
reference lvalue of T
const_reference const lvalue of T
iterator iterator pointing to T ForwardIterator
convertible to const_iterator
const_iterator const iterator pointing to T ForwardIterator
difference_type signed integer must be the same as iterator_traits::difference_type for iterator and const_iterator
size_type unsigned integer large enough to represent all positive values of difference_type

[править] Методы и операторы

expression return type semantics conditions complexity
C(); C Creates an empty container Post: u.empty() == true Constant
C(a) C Create a copy of a Pre: T must be CopyInsertable
Post: a == X(a)
Linear
a = b C& All elements of a are destroyed or move assigned to elements of b Post: a == b Linear
(&a)->~C() void Destroy all elements and free all memory Linear
a.begin() (const_)iterator Iterator to the first element Constant
a.end() (const_)iterator Iterator to one passed the last element Constant
a.cbegin()(начиная с C++11) const_iterator const_cast<const C&>(a).begin() Constant
a.cend()(начиная с C++11) const_iterator const_cast<const C&>(a).end() Constant
a == b convertible to bool Makes C EqualityComparable Pre: T must be EqualityComparable Linear
a != b convertible to bool !(a==b) Linear
a.swap(b) void exchanges the values of a and b Constant[1][2]
swap(a,b) void a.swap(b) Constant[1]
a.size() size_type distance(a.begin(),a.end()) Constant[2]
a.max_size() size_type b.size() where b is the largest possible container Constant[2]
a.empty() convertible to bool a.begin() == a.end() Constant
notes
  1. 1,0 1,1 (начиная с C++11) Linear for std::array
  2. 2,0 2,1 2,2 (до C++11) Not strictly constant

[править] Контейнер данных гонок

Реализации не обязаны предоставлять любые гарантии повторного входа для последовательного изменения - это не безопасно push_back и читать begin одновременно. Тем не менее, это необходимо, чтобы избежать гонки данных, когда содержание объектов, содержащихся в различных элементах той же последовательности изменяются одновременно (за исключением vector<bool>). Иными словами, для vector<int> с размером больше 1, x[1] = 5 и *x.begin() = 10 не приведет к гонке данных.
Оригинал:
Implementations are not required to provide any reentrancy guarantee for sequence modifications - it is not safe to push_back and read begin concurrently. However, it is required to avoid data races when the contents of the contained object in different elements of the same sequence are modified concurrently (except for vector<bool>). In other words, for a vector<int> with size greater than 1, x[1] = 5 and *x.begin() = 10 will not result in a data race.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Эти функции также должны быть рассмотрены const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at, и, за исключением AssociativeContainer и UnorderedAssociativeContainer, operator[]. Вызов любой из этих функций одновременно не приведет к гонке данных.
Оригинал:
These functions must also be considered const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at, and, except in AssociativeContainer and UnorderedAssociativeContainer, operator[]. Calling any of these functions concurrently will not result in a data race.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.

[править] Другие понятия

C
T