Struct template segmented_vector



// In header: <boost/text/segmented_vector_fwd.hpp>

template<typename T, typename Segment> 
struct segmented_vector {
  // construct/copy/destruct
  segmented_vector() noexcept;
  explicit segmented_vector(size_type);
  explicit segmented_vector(size_type, T const &);
  template<typename Iter, typename Sentinel> segmented_vector(Iter, Sentinel);
  segmented_vector(std::initializer_list< T >);
  segmented_vector(segmented_vector const &) = default;
  segmented_vector(segmented_vector &&);
  segmented_vector & operator=(segmented_vector const &) = default;
  segmented_vector & operator=(segmented_vector &&);

  // public member functions
  const_iterator begin() noexcept;
  const_iterator end() noexcept;
  size_type size() const noexcept;
  size_type max_size() const noexcept;
  void resize(size_type) noexcept;
  void resize(size_type, T const &) noexcept;
  template<typename Iter, typename Sentinel> void assign(Iter, Sentinel);
  template<typename Iter> void assign(size_type, T const &);
  template<typename... Args> const_reference emplace_front(Args &&...);
  template<typename... Args> const_reference emplace_back(Args &&...);
  template<typename... Args> 
    const_iterator emplace(const_iterator, Args &&...);
  template<typename Iter, typename Sentinel> 
    const_iterator insert(const_iterator, Iter, Sentinel);
  const_iterator insert(const_iterator, segment_type);
  const_iterator erase(const_iterator, const_iterator);
  void swap(segmented_vector &);
  bool equal_root(segmented_vector) const noexcept;
  segmented_vector & replace(const_iterator, T);
  segmented_vector & replace(const_iterator, const_iterator, segment_type);
  template<typename Iter, typename Sentinel> 
    segmented_vector & replace(const_iterator, const_iterator, Iter, Sentinel);
  template<typename Fn> void foreach_segment(Fn &&) const;


A sequence container of T with discontiguous storage. Insertion and erasure are efficient at any position within the sequence, and copies of the entire container are extremely cheap. The elements are immutable. In order to "mutate" one, use the single-element overload of replace().

segmented_vector public construct/copy/destruct

  1. segmented_vector() noexcept;

    Default ctor.


    size() == 0 && begin() == end()

  2. explicit segmented_vector(size_type n);
  3. explicit segmented_vector(size_type n, T const & x);
  4. template<typename Iter, typename Sentinel> 
      segmented_vector(Iter first, Sentinel last);
  5. segmented_vector(std::initializer_list< T > il);
  6. segmented_vector(segmented_vector const &) = default;
  7. segmented_vector(segmented_vector &&);
  8. segmented_vector & operator=(segmented_vector const &) = default;
  9. segmented_vector & operator=(segmented_vector &&);
  10. ~segmented_vector();

segmented_vector public member functions

  1. const_iterator begin() noexcept;
  2. const_iterator end() noexcept;
  3. size_type size() const noexcept;
  4. size_type max_size() const noexcept;
  5. void resize(size_type sz) noexcept;
  6. void resize(size_type sz, T const & x) noexcept;
  7. template<typename Iter, typename Sentinel> 
      void assign(Iter first, Sentinel last);
  8. template<typename Iter> void assign(size_type n, T const & x);
  9. template<typename... Args> const_reference emplace_front(Args &&... args);
  10. template<typename... Args> const_reference emplace_back(Args &&... args);
  11. template<typename... Args> 
      const_iterator emplace(const_iterator at, Args &&... args);
  12. template<typename Iter, typename Sentinel> 
      const_iterator insert(const_iterator at, Iter first, Sentinel last);
  13. const_iterator insert(const_iterator at, segment_type v);
  14. const_iterator erase(const_iterator first, const_iterator last);
  15. void swap(segmented_vector & other);
  16. bool equal_root(segmented_vector other) const noexcept;

    Returns true if *this and other contain the same root node pointer. This is useful when you want to check for equality between two segmented_vectors that are likely to have originated from the same initial segmented_vector, and may have since been mutated.

  17. segmented_vector & replace(const_iterator at, T t);

    Replaces the element at position at with t, by moving t.

    If *this hold the only reference to the underlying data, this is more efficient than calling erase() in combination with insert().


    begin() <= old_substr.begin() && old_substr.end() <= end()

  18. segmented_vector & 
    replace(const_iterator first, const_iterator last, segment_type v);

    Replaces the portion of *this delimited by [first, last) with the sequence of T from v by moving the contents of v.


    begin() <= old_substr.begin() && old_substr.end() <= end()

  19. template<typename Iter, typename Sentinel> 
      segmented_vector & 
      replace(const_iterator old_first, const_iterator old_last, Iter new_first, 
              Sentinel new_last);

    Replaces the portion of *this delimited by [old_first, old_last) with the T sequence [new_first, new_last).


    begin() <= old_substr.begin() && old_substr.end() <= end()

  20. template<typename Fn> void foreach_segment(Fn && f) const;

    Visits each segment s of *this and calls f(s). Each segment is a string_view. Depending of the operation performed on each segment, this may be more efficient than iterating over [begin(), end()).


    Fn is an invocable accepting an iterator and a sentinel.