Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Class template static_vector

Boost , The Boost C++ Libraries BoostBook Documentation Subset , Boost.Container Header Reference

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class template static_vector

boost::container::static_vector — A variable-size array container with fixed capacity.

Synopsis

// In header: <boost/container/static_vector.hpp>
template<typename Value, std::size_t Capacity> 
class static_vector {
public:
  // types
  typedef base_t::value_type             value_type;              // The type of elements stored in the container. 
  typedef base_t::size_type              size_type;               // The unsigned integral type used by the container. 
  typedef base_t::difference_type        difference_type;         // The pointers difference type. 
  typedef base_t::pointer                pointer;                 // The pointer type. 
  typedef base_t::const_pointer          const_pointer;           // The const pointer type. 
  typedef base_t::reference              reference;               // The value reference type. 
  typedef base_t::const_reference        const_reference;         // The value const reference type. 
  typedef base_t::iterator               iterator;                // The iterator type. 
  typedef base_t::const_iterator         const_iterator;          // The const iterator type. 
  typedef base_t::reverse_iterator       reverse_iterator;        // The reverse iterator type. 
  typedef base_t::const_reverse_iterator const_reverse_iterator;  // The const reverse iterator. 
  // construct/copy/destruct
  static_vector() noexcept;
  explicit static_vector(size_type);
  static_vector(size_type, default_init_t);
  static_vector(size_type, value_type const &);
  template<typename Iterator> static_vector(Iterator, Iterator);
  static_vector(std::initializer_list< value_type >);
  static_vector(static_vector const &);
  template<std::size_t C> 
    static_vector(static_vector< value_type, C > const &);
  static_vector(static_vector &&) noexcept(boost::container::container_detail::is_nothrow_move_constructible< value_type >::value));
  template<std::size_t C> static_vector(static_vector< value_type, C > &&);
  static_vector & operator=(const static_vector &);
  static_vector & operator=(std::initializer_list< value_type >);
  template<std::size_t C> 
    static_vector & operator=(static_vector< value_type, C > const &);
  static_vector & operator=(static_vector &&);
  template<std::size_t C> 
    static_vector & operator=(static_vector< value_type, C > &&);
  ~static_vector();
  // public member functions
  void swap(static_vector &);
  template<std::size_t C> void swap(static_vector< value_type, C > &);
  void resize(size_type);
  void resize(size_type, default_init_t);
  void resize(size_type, value_type const &);
  void reserve(size_type) noexcept;
  void push_back(value_type const &);
  void push_back(value_type &&);
  void pop_back();
  iterator insert(const_iterator, value_type const &);
  iterator insert(const_iterator, value_type &&);
  iterator insert(const_iterator, size_type, value_type const &);
  template<typename Iterator> 
    iterator insert(const_iterator, Iterator, Iterator);
  iterator insert(const_iterator, std::initializer_list< value_type >);
  iterator erase(const_iterator);
  iterator erase(const_iterator, const_iterator);
  template<typename Iterator> void assign(Iterator, Iterator);
  void assign(std::initializer_list< value_type >);
  void assign(size_type, value_type const &);
  template<class... Args> reference emplace_back(Args &&...);
  template<class... Args> iterator emplace(const_iterator, Args &&...);
  void clear() noexcept;
  reference at(size_type);
  const_reference at(size_type) const;
  reference operator[](size_type);
  const_reference operator[](size_type) const;
  iterator nth(size_type);
  const_iterator nth(size_type) const;
  size_type index_of(iterator);
  size_type index_of(const_iterator) const;
  reference front();
  const_reference front() const;
  reference back();
  const_reference back() const;
  Value * data() noexcept;
  const Value * data() const noexcept;
  iterator begin() noexcept;
  const_iterator begin() const noexcept;
  const_iterator cbegin() const noexcept;
  iterator end() noexcept;
  const_iterator end() const noexcept;
  const_iterator cend() const noexcept;
  reverse_iterator rbegin() noexcept;
  const_reverse_iterator rbegin() const noexcept;
  const_reverse_iterator crbegin() const noexcept;
  reverse_iterator rend() noexcept;
  const_reverse_iterator rend() const noexcept;
  const_reverse_iterator crend() const noexcept;
  size_type size() const noexcept;
  bool empty() const noexcept;
  // public static functions
  static size_type capacity() noexcept;
  static size_type max_size() noexcept;
  // public data members
  static const size_type static_capacity;  // The capacity/max size of the container. 
};

Description

static_vector- контейнер последовательностей,бустер::контейнер::векторс непрерывным хранилищем, которое может изменяться в размерах, наряду со статическим распределением, низкими накладными расходами и фиксированной емкостью наддува:

А.статичный вектор- последовательность, которая поддерживает случайный доступ к элементам, постоянную вставку времени и удаление элементов в конце и линейную вставку времени и удаление элементов в начале или в середине. Число элементов вstatic_vectorможет динамически изменяться до фиксированной емкости, поскольку элементы хранятся внутри самого объекта аналогично массиву. Однако объекты инициализируются по мере их вставки вstatic_vector.В отличие от C-массивов или std::array, которые должны конструировать все элементы при инстанциации. Поведениеstatic_vectorпозволяет использовать статически выделенные элементы в случаях со сложными требованиями к жизни объекта, которые в противном случае были бы не тривиально возможны.

Обработка ошибок. Включение за пределы емкости приводит к метанию std::bad_alloc(), если включены исключения или вызову throw_bad_alloc(), если не включен.

std::out_of_range выбрасывается, если ограниченный доступ выполнен в<at()>, если включены исключения, throw_out_of_range() если не включен.

Template Parameters

  1. Типтейт,

    .

    typenameValue

    Тип элемента, который будет храниться.

    [ORIG_END] -->[ORIG_END] -->
  2. std::size_tCapacity

    Максимальное количество элементовstatic_vectorможет храниться, фиксируется во время компиляции.

static_vector public construct/copy/destruct

  1. static_vector()noexcept;
    Постраивает пустоеstatic_vector.

    Бросает. Ничего.

    Сложность. Постоянная О(1).

  2. explicit static_vector(size_type count);
    Constructs a static_vector containing count value initialized values.

    Throws. If Value's value initialization throws.

    Сложность. Линейный O(N).

    Параметры:

    count

    The number of values which will be contained in the container.

    Требуется:

    count <= capacity()

  3. static_vector(size_type count, default_init_t);
    Constructs a static_vector containing count default initialized values.

    Throws. If Value's default initialization throws.

    Complexity. Linear O(N).

    Note. Non-standard extension

    Параметры:

    count

    The number of values which will be contained in the container.

    Требуется:

    count <= capacity()

  4. static_vector(size_type count, value_type const & value);
    Constructs a static_vector containing count copies of value.

    Throws. If Value's copy constructor throws.

    Сложность. Линейный O(N).

    Параметры:

    count

    The number of copies of a values that will be contained in the container.

    <value>

    The value which will be used to copy construct values.

    Требуется:

    count <= capacity()

  5. template<typename Iterator> static_vector(Iterator first, Iterator last);
    Constructs a static_vector containing copy of a range [first, last).

    Throws. If Value's constructor taking a dereferenced Iterator throws.

    Сложность. Линейный O(N).

    Параметры:

    first

    The iterator to the first element in range.

    <last>

    The iterator to the one after the last element in range.

Требуется:

  • distance(first, last) <= capacity()

  • Итератор должен соответствовать концепции<ForwardTraversalIterator>.

  • static_vector(std::initializer_list< value_type > il);
    Constructs a static_vector containing copy of a range [il.begin(), il.end()).

    Throws. If Value's constructor taking a dereferenced std::initializer_list throws.

    Сложность. Линейный O(N).

    Параметры:

    il

    std::initializer_list with values to initialize vector.

    Требуется:

    • distance(il.begin(), il.end()) <= capacity()

  • static_vector(static_vector const & other);
    Constructs a copy of other static_vector.

    Throws. If Value's copy constructor throws.

    Сложность. Линейный O(N).

    Параметры:

    other

    The static_vector which content will be copied to this one.

  • template<std::size_t C> 
      static_vector(static_vector< value_type, C > const & other);
    Constructs a copy of other static_vector.

    Throws. If Value's copy constructor throws.

    Сложность. Линейный O(N).

    Параметры:

    other

    The static_vector which content will be copied to this one.

    Требуется:

    other.size() <= capacity().

  • static_vector(static_vector&&other)noexcept(boost::container::container_detail::is_nothrow_move_constructible<value_type>::value));
    Переместить конструктор. Двигаться При этом в другомstatic_vector.

    Бросок. 

    Сложность. Линейный O(N).

    Параметры:

    other

    <static_vector>, содержание которого будет перенесено на это.

  • template<std::size_tC>static_vector(static_vector<value_type,C>&&other);
    Переместить конструктор. Двигаться При этом в другомstatic_vectorзначении.

    Бросок. 

    Сложность. Линейный O(N).

    Параметры:

    other

    <static_vector>, содержание которого будет перенесено на это.

    Требуется:

    <other.size() <= capacity()>

  • static_vector & operator=(const static_vector & other);
    Copy assigns Values stored in the other static_vector to this one.

    Throws. If Value's copy constructor or copy assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    other

    The static_vector which content will be copied to this one.

  • static_vector & operator=(std::initializer_list< value_type > il);
    Copy assigns Values stored in std::initializer_list to *this.

    Throws. If Value's copy constructor or copy assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    il

    The std::initializer_list which content will be copied to this one.

  • template<std::size_t C> 
      static_vector & operator=(static_vector< value_type, C > const & other);
    Copy assigns Values stored in the other static_vector to this one.

    Throws. If Value's copy constructor or copy assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    other

    The static_vector which content will be copied to this one.

    Требуется:

    <other.size() <= capacity()>

  • Бросает.

    Сложность. Линейный O(N).

    Параметры:

    other

    <static_vector>, содержание которого будет перенесено на это.

  • template<std::size_tC>
     static_vector&operator=(static_vector<value_type,C>&&other);
    Перейдите к делу. Двигаться В другом случаеstatic_vector.

    Бросок. 

    Сложность. Линейный O(N).

    Параметры:

    other

    <static_vector>, содержание которого будет перенесено на это.

    Требуется:

    <other.size() <= capacity()>

  • ~static_vector();
    Destructor. Destroys Values stored in this container.

    Throws. Nothing

    Сложность. Линейный O(N).

  • static_vector public member functions

    1. voidswap(static_vector&other);
      Своп-содержимое другогоstatic_vectorи этого.

      Броски. 

      • Еслиhas_nothrow_move<Value>::valueявляетсяtrueи ход Значения конструктора или ход назначения бросков,

      • Если<has_nothrow_move<Value>::value>является<false>и конструктором копии или броском копирования Value,

      Сложность. Линейный O(N).

      Параметры:

      other

      <static_vector>, содержание которого будет заменено содержанием этого.

  • template<std::size_tC>voidswap(static_vector<value_type,C>&other);
    Своп-содержимое другогоstatic_vectorи этого.

    Бросок. 

    • Еслиhas_nothrow_move<Value>::valueявляетсяtrueи ход Значения конструктора или ход назначения бросков,

    • Если<has_nothrow_move<Value>::value>является<false>и конструктором копии или броском копирования Value,

    Сложность. Линейный O(N).

    Параметры:

    other

    <static_vector>, содержание которого будет заменено содержанием этого.

    Требуется:

    <other.size() <= capacity() && size() <= other.capacity()>

  • void resize(size_type count);
    Inserts or erases elements at the end such that the size becomes count. New elements are value initialized.

    Throws. If Value's value initialization throws.

    Сложность. Линейный O(N).

    Параметры:

    count

    The number of elements which will be stored in the container.

    Требуется:

    count <= capacity()

  • void resize(size_type count, default_init_t);
    Inserts or erases elements at the end such that the size becomes count. New elements are default initialized.

    Throws. If Value's default initialization throws.

    Complexity. Linear O(N).

    Note. Non-standard extension

    Параметры:

    count

    The number of elements which will be stored in the container.

    Требуется:

    count <= capacity()

  • void resize(size_type count, value_type const & value);
    Inserts or erases elements at the end such that the size becomes count. New elements are copy constructed from value.

    Throws. If Value's copy constructor throws.

    Сложность. Линейный O(N).

    Параметры:

    count

    The number of elements which will be stored in the container.

    <value>

    Значение, используемое для копирования конструкции нового элемента.

    Требуется:

    count <= capacity()

  • void reserve(size_type count) noexcept;
    This call has no effect because the Capacity of this container is constant.

    Throws. Nothing.

    Сложность. Линейный O(N).

    Параметры:

    count

    The number of elements which the container should be able to contain.

    Требуется:

    count <= capacity()

  • void push_back(value_type const & value);
    Adds a copy of value at the end.

    Throws. If Value's copy constructor throws.

    Complexity. Constant O(1).

    Параметры:

    <value>

    Значение, используемое для копирования конструкции нового элемента.

    Требуется:

    <size() < capacity()>

  • void push_back(value_type && value);
    Moves value to the end.

    Throws. If Value's move constructor throws.

    Complexity. Constant O(1).

    Параметры:

    <value>

    The value to move construct the new element.

    Требуется:

    <size() < capacity()>

  • void pop_back();
    Destroys last value and decreases the size.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Требуется:

    !empty()

  • iteratorinsert(const_iteratorp,value_typeconst&value);
    Вставляется копия элемента по п.

    Бросок. 

    Сложность. Постоянная или линейная.

    Параметры:

    <p>

    Положение, в которое будет вставлено новое значение.

    <value>

    Значение, используемое для копирования конструкции нового элемента.

    Требуется:

  • iterator insert(const_iterator p, value_type && value);
    Inserts a move-constructed element at p.

    Throws. If Value's move constructor or move assignment throws.

    Сложность. Постоянная или линейная.

    Параметры:

    <p>

    Положение, в которое будет вставлено новое значение.

    <value>

    The value used to move construct the new element.

    Требуется:

  • Броски.

  • Броски.

    Сложность. Линейный O(N).

    Параметры:

    il

    Std::initializer_list содержит элементы, которые будут вставлены.

    <p>

    Положение, в которое будут вставлены новые элементы.

    Требуется:

    • pдолжен быть действительным итератором*thisв диапазоне[begin(), end()]

      .
    • distance(il.begin(), il.end()) <= capacity()

  • iterator erase(const_iterator p);
    Erases Value from p.

    Throws. If Value's move assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    <p>

    The position of the element which will be erased from the container.

    Требуется:

    p must be a valid iterator of *this in range [begin(), end())

  • iterator erase(const_iterator first, const_iterator last);
    Erases Values from a range [first, last).

    Throws. If Value's move assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    first

    The position of the first element of a range which will be erased from the container.

    <last>

    The position of the one after the last element of a range which will be erased from the container.

    Требуется:

  • template<typename Iterator> void assign(Iterator first, Iterator last);
    Assigns a range [first, last) of Values to this container.

    Throws. If Value's copy constructor or copy assignment throws,

    Сложность. Линейный O(N).

    Параметры:

    first

    The iterator to the first element of a range used to construct new content of this container.

    <last>

    The iterator to the one after the last element of a range used to construct new content of this container.

    Требуется:

    distance(first, last) <= capacity()

  • Throws.  Если конструктор копий или присвоение копий Value бросает,

    Complexity. Linear O(N).

    Параметры:

    il

    std::initializer_list с значениями, используемыми для создания нового содержания этого контейнера.

    Требования:

    distance(il.begin(), il.end()) <= capacity()

    Сложность. Линейный O(N).

    Параметры:

    il

    std::initializer_list with values used to construct new content of this container.

    Требуется:

    distance(il.begin(), il.end()) <= capacity()

    [ORIG_END] -->
  • void assign(size_type count, value_type const & value);
    Assigns a count copies of value to this container.

    Throws. If Value's copy constructor or copy assignment throws.

    Сложность. Линейный O(N).

    Параметры:

    count

    The new number of elements which will be container in the container.

    <value>

    The value which will be used to copy construct the new content.

    Требуется:

    count <= capacity()

  • template<class... Args> reference emplace_back(Args &&... args);
    Inserts a Value constructed with std::forward<Args>(args)... in the end of the container.

    Throws. If in-place constructor throws or Value's move constructor throws.

    Complexity. Constant O(1).

    Параметры:

    args

    The arguments of the constructor of the new element which will be created at the end of the container.

    Требуется:

    <size() < capacity()>

    Returns:

    A reference to the created object.

  • template<class... Args> iterator emplace(const_iterator p, Args &&... args);
    Inserts a Value constructed with std::forward<Args>(args)... before p.

    Throws. If in-place constructor throws or if Value's move constructor or move assignment throws.

    Сложность. Постоянная или линейная.

    Параметры:

    args

    The arguments of the constructor of the new element.

    <p>

    Положение, в которое будут вставлены новые элементы.

    Требуется:

    • p must be a valid iterator of *this in range [begin(), end()]

    • <size() < capacity()>

  • voidclear()noexcept;
    Удалить все элементы из контейнера.

    Броски. Ничего.

    Сложность. Постоянная О(1).

  • Throws. std::out_of_range исключение по умолчанию.

    Сложность. Состояние O(1).

    Параметры:

    i

    Указатель элемента.

    Требования:

    i < size()

    Возвращение:

    ссылка на i-й элемент с начала контейнера.

    Параметры:

    i

    The element's index.

    Требуется:

    i < size()

    Returns:

    reference to the i-th element from the beginning of the container.

    [ORIG_END] -->
  • const_reference at(size_type i) const;
    Returns const reference to the i-th element.

    Throws. std::out_of_range exception by default.

    Complexity. Constant O(1).

    Параметры:

    i

    The element's index.

    Требуется:

    i < size()

    Returns:

    const reference to the i-th element from the beginning of the container.

  • reference operator[](size_type i);
    Returns reference to the i-th element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Параметры:

    i

    The element's index.

    Требуется:

    i < size()

    Returns:

    reference to the i-th element from the beginning of the container.

  • const_reference operator[](size_type i) const;
    Returns const reference to the i-th element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Параметры:

    i

    The element's index.

    Требуется:

    i < size()

    Returns:

    const reference to the i-th element from the beginning of the container.

  • iterator nth(size_type i);
    Returns a iterator to the i-th element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Параметры:

    i

    The element's index.

    Требуется:

    i =< size()

    Returns:

    a iterator to the i-th element.

  • const_iterator nth(size_type i) const;
    Returns a const_iterator to the i-th element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Параметры:

    i

    The element's index.

    Требуется:

    i =< size()

    Returns:

    a const_iterator to the i-th element.

  • size_type index_of(iterator p);
    Returns the index of the element pointed by p.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Параметры:

    <p>

    An iterator to the element.

    Требуется:

    begin() <= p <= end()

    Returns:

    The index of the element pointed by p.

  • Throws. Ничего по умолчанию.

    Сложность. Состояние O(1).

    Параметры:

    <p>

    Конструктор для элемента.

    Требования:

    begin() <= p <= end()

    Возвращение:

    a const_iterator to the i-th element.

    Параметры:

    <p>

    A const_iterator to the element.

    Требуется:

    begin() <= p <= end()

    Returns:

    a const_iterator to the i-th element.

    [ORIG_END] -->
  • reference front();
    Returns reference to the first element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Требуется:

    !empty()

    Returns:

    reference to the first element from the beginning of the container.

  • const_reference front() const;
    Returns const reference to the first element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Требуется:

    !empty()

    Returns:

    const reference to the first element from the beginning of the container.

  • reference back();
    Returns reference to the last element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Требуется:

    !empty()

    Returns:

    reference to the last element from the beginning of the container.

  • const_reference back() const;
    Returns const reference to the first element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Требуется:

    !empty()

    Returns:

    const reference to the last element from the beginning of the container.

  • Value*data()noexcept;
    Указатель такой, что[data(), data() + size())является допустимым диапазоном. Для непустого вектораdata() == &front().

    Броски. Ничего.

    Сложность. Постоянная O(1).

  • constValue*data()constnoexcept;
    Конст-указатель таков, что[data(), data() + size())является допустимым диапазоном. Для непустого вектораdata() == &front().

    Броски. Ничего.

    Сложность. Константа O(1).

  • iteratorbegin()noexcept;
    Возвращает итератор в первый элемент.

    Бросок. Ничего.

    Сложность. Константа O(1).

    итератор к первому элементу, содержащемуся в векторе.

  • const_iteratorbegin()constnoexcept;
    Возвращает конст-итератор в первый элемент.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возвращает:

    const_iterator к первому элементу, содержащемуся в векторе.

  • const_iteratorcbegin()constnoexcept;
    Возвращает итератор к первому элементу.

    Броски. Ничего.

    Сложность. Постоянная О(1).

    Возвращает:

    const_iterator к первому элементу, содержащемуся в векторе.

  • iteratorend()noexcept;
    Возвращает итератор к итератору после последнего элемента.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возвращается:

    итератор, указывающий на один после последнего элемента, содержащегося в векторе.

  • const_iteratorend()constnoexcept;
    Возвращает конст-итератор к тому, что следует за последним элементом.

    Броски. Ничего.

    Сложность. Константа О(1).

    Возвращает:

    const_iterator, указывающий на один после последнего элемента, содержащегося в векторе.

  • const_iteratorcend()constnoexcept;
    Возвращает конст-итератор к тому, что следует за последним элементом.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возвращает:

    const_iterator, указывающий на один после последнего элемента, содержащегося в векторе.

  • reverse_iteratorrbegin()noexcept;
    Возвращает обратный итератор к первому элементу обратного контейнера.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возврат:

    reverse_iterator, указывающий на начало обратногоstatic_vector.

  • const_reverse_iteratorrbegin()constnoexcept;
    Возвращает обратный итератор к первому элементу обратного контейнера.

    Броски. Ничего.

    Сложность. Константа O(1).

    const_reverse_iterator, указывающий на начало обратногостатического_вектора.

    const_reverse_iteratorrbegin()constnoexcept;
  • const_reverse_iteratorcrbegin()constnoexcept;
    Возвращает обратный итератор к первому элементу обратного контейнера.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возвращение:

    const_reverse_iterator, указывающий на начало обратногостатического_вектора.

  • reverse_iteratorrend()noexcept;
    Возвращает обратный итератор к тому, который следует за последним элементом обратного контейнера.

    Броски. Ничего.

    Сложность. Константа O(1).

    Возврат:

    reverse_iterator, указывающий на один после последнего элемента обратногоstatic_vector.

  • const_reverse_iteratorrend()constnoexcept;
    Возвращает конст-реверсивный итератор в тот, который расположен после последнего элемента реверсивного контейнера.

    Броски. Ничто.

    Сложность. Константа O(1).

    Возврат:

    const_reverse_iterator, указывающий на один после последнего элемента обратногоstatic_vector.

  • const_reverse_iteratorcrend()constnoexcept;
    Возвращает конст-реверсивный итератор в тот, который расположен после последнего элемента реверсивного контейнера.

    Броски.ʸ] Ничего.

    Сложность. Константа O(1).