boost::text::segmented_vector
// In header: <boost/text/segmented_vector.hpp> template<typename T, typename Segment> struct segmented_vector : public boost::stl_interfaces::sequence_container_interface< segmented_vector< T, Segment >, boost::stl_interfaces::element_layout::discontiguous > { // types typedef T value_type; typedef T * pointer; typedef T const * const_pointer; typedef value_type const & reference; typedef reference const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef unspecified iterator; typedef iterator const_iterator; typedef stl_interfaces::reverse_iterator< iterator > reverse_iterator; typedef reverse_iterator const_reverse_iterator; typedef Segment segment_type; typedef boost::stl_interfaces::sequence_container_interface< segmented_vector< T, Segment >, boost::stl_interfaces::element_layout::discontiguous > base_type; // construct/copy/destruct segmented_vector(); 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 &&); ~segmented_vector(); // public member functions const_iterator begin(); const_iterator end(); size_type size() const; size_type max_size() const; void resize(size_type); void resize(size_type, T const &); 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; 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/destructsegmented_vector();
Default ctor.
Postconditions: |
|
explicit segmented_vector(size_type n);
explicit segmented_vector(size_type n, T const & x);
template<typename Iter, typename Sentinel> segmented_vector(Iter first, Sentinel last);
segmented_vector(std::initializer_list< T > il);
segmented_vector(segmented_vector const &) = default;
segmented_vector(segmented_vector &&);
segmented_vector & operator=(segmented_vector const &) = default;
segmented_vector & operator=(segmented_vector &&);
~segmented_vector();
segmented_vector
public member functionsconst_iterator begin();
const_iterator end();
size_type size() const;
size_type max_size() const;
void resize(size_type sz);
void resize(size_type sz, T const & x);
template<typename Iter, typename Sentinel> void assign(Iter first, Sentinel last);
template<typename Iter> void assign(size_type n, T const & x);
template<typename... Args> const_reference emplace_front(Args &&... args);
template<typename... Args> const_reference emplace_back(Args &&... args);
template<typename... Args> const_iterator emplace(const_iterator at, Args &&... args);
template<typename Iter, typename Sentinel> const_iterator insert(const_iterator at, Iter first, Sentinel last);
const_iterator insert(const_iterator at, segment_type v);
const_iterator erase(const_iterator first, const_iterator last);
void swap(segmented_vector & other);
bool equal_root(segmented_vector other) const;
Returns true if *this
and other
contain the same root node pointer. This is useful when you want to check for equality between two
s that are likely to have originated from the same initial segmented_vector
, and may have since been mutated. segmented_vector
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()
.
Requires: |
|
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
.
Requires: |
|
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)
.
Requires: |
|
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()).
Requires: |
Fn is an invocable accepting an iterator and a sentinel. |