Table of Contents
- Summary
- Template Parameters
- Public Member Types
- Public Data Members
- Public Member Functions
- (constructor)
- (destructor)
- assign
- operator=
- get_allocator
- begin, cbegin
- end, cend
- rbegin, crbegin
- rend, crend
- nth
- index_of
- empty
- size
- max_size
- capacity
- available_front
- available_back
- reserve_front
- reserve_back
- shrink_to_fit
- at
- operator[]
- front
- back
- clear
- emplace
- insert
- emplace_front
- emplace_back
- push_front
- push_back
- pop_front
- pop_back
- erase
- resize
- resize_front
- resize_back
- swap
- Non-member Functions
Defined in header sfl/segmented_devector.hpp
:
namespace sfl
{
template < typename T,
std::size_t N,
typename Allocator = std::allocator<T> >
class segmented_devector;
}
sfl::segmented_devector
(segmented double-ended vector) is a sequence container similar to std::deque
that allows fast insertion and deletion at both its beginning and its end.
The storage of segmented double-ended vector consists of a sequence of individually allocated arrays of size N
which are referred to as segments. Elements of segmented double-ended vector are not stored contiguously in the memory, but they are stored contiguously within a segment. Size N
is specified at the compile time as a template parameter.
Iterators to elements are random access iterators and they meet the requirements of LegacyRandomAccessIterator.
Indexed access to elements (operator[]
and at
) must perform two pointer dereferences.
sfl::segmented_devector
is not specialized for bool
.
sfl::segmented_devector
meets the requirements of Container, AllocatorAwareContainer, ReversibleContainer and SequenceContainer.
Key differences between segmented_vector
and segmented_devector
:
segmented_vector
allows fast insertion and deletion only at its end andsegmented_devector
allows fast insertion and deletion at both its beginning and its end.segmented_vector
has much faster random access (nth
,operator[]
andat
) thansegmented_devector
.
-
typename T
The type of the elements.
-
std::size_t N
Segment size, i.e. the maximal number of elements that can fit into a segment.
This parameter must be greater than zero.
-
typename Allocator
Allocator used for memory allocation/deallocation and construction/destruction of elements.
This type must meet the requirements of Allocator.
The program is ill-formed if
Allocator::value_type
is not the same asT
.
Member Type | Definition |
---|---|
allocator_type |
Allocator |
allocator_traits |
std::allocator_traits<Allocator> |
value_type |
T |
size_type |
typename allocator_traits::size_type |
difference_type |
typename allocator_traits::difference_type |
reference |
T& |
const_reference |
const T& |
pointer |
typename allocator_traits::pointer |
const_pointer |
typename allocator_traits::const_pointer |
iterator |
LegacyRandomAccessIterator to value_type |
const_iterator |
LegacyRandomAccessIterator to const value_type |
reverse_iterator |
std::reverse_iterator<iterator> |
const_reverse_iterator |
std::reverse_iterator<const_iterator> |
static constexpr size_type segment_capacity = N;
-
segmented_devector();
-
explicit segmented_devector(const Allocator& alloc);
Effects: Constructs an empty container.
Complexity: Constant.
-
segmented_devector(size_type n);
-
explicit segmented_devector(size_type n, const Allocator& alloc);
Effects: Constructs the container with
n
default-constructed elements.Complexity: Linear in
n
. -
segmented_devector(size_type n, const T& value);
-
segmented_devector(size_type n, const T& value, const Allocator& alloc);
Effects: Constructs the container with
n
copies of elements with valuevalue
.Complexity: Linear in
n
. -
template <typename InputIt> segmented_devector(InputIt first, InputIt last);
-
template <typename InputIt> segmented_devector(InputIt first, InputIt last, const Allocator& alloc);
Effects: Constructs the container with the contents of the range
[first, last)
.Note: This overload participates in overload resolution only if
InputIt
satisfies requirements of LegacyInputIterator.Complexity: Linear in
std::distance(first, last)
. -
segmented_devector(std::initializer_list<T> ilist);
-
segmented_devector(std::initializer_list<T> ilist, const Allocator& alloc);
Effects: Constructs the container with the contents of the initializer list
ilist
.Complexity: Linear in
ilist.size()
. -
segmented_devector(const segmented_devector& other);
-
segmented_devector(const segmented_devector& other, const Allocator& alloc);
Effects: Copy constructor. Constructs the container with the copy of the contents of
other
.Complexity: Linear in
other.size()
. -
segmented_devector(segmented_devector&& other);
-
segmented_devector(segmented_devector&& other, const Allocator& alloc);
Effects: Move constructor. Constructs the container with the contents of
other
using move semantics.- Overload (13):
other
is guaranteed to be empty after the move.
- Overload (14):
other
is not guaranteed to be empty after the move.other
is in a valid but unspecified state after the move.
Complexity:
- Overload (13): Constant.
- Overload (14): Constant if
alloc == other.get_alloc()
, otherwise linear.
- Overload (13):
-
~segmented_devector();
Effects: Destructs the container. The destructors of the elements are called and the used storage is deallocated.
Complexity: Linear in
size()
.
-
void assign(size_type n, const T& value);
Effects: Replaces the contents of the container with
n
copies of valuevalue
.Complexity: Linear in
n
. -
template <typename InputIt> void assign(InputIt first, InputIt last);
Effects: Replaces the contents of the container with the contents of the range
[first, last)
.Note: This overload participates in overload resolution only if
InputIt
satisfies requirements of LegacyInputIterator.Note: The behavior is undefined if either
first
orlast
is an iterator into*this
.Complexity: Linear in
std::distance(first, last)
. -
void assign(std::initializer_list<T> ilist);
Effects: Replaces the contents of the container with the contents of the initializer list
ilist
.Complexity: Linear in
ilist.size()
.
-
segmented_devector& operator=(const segmented_devector& other);
Effects: Copy assignment operator. Replaces the contents with a copy of the contents of
other
.Returns:
*this
. -
segmented_devector& operator=(segmented_devector&& other);
Effects: Move assignment operator. Replaces the contents with those of
other
using move semantics.other
is not guaranteed to be empty after the move.other
is in a valid but unspecified state after the move.Returns:
*this
. -
segmented_devector& operator=(std::initializer_list<T> ilist);
Effects: Replaces the contents with those identified by initializer list
ilist
.Returns:
*this
.
-
allocator_type get_allocator() const noexcept;
Effects: Returns the allocator associated with the container.
Complexity: Constant.
-
iterator begin() noexcept;
-
const_iterator begin() const noexcept;
-
const_iterator cbegin() const noexcept;
Effects: Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to
end()
.Complexity: Constant.
-
iterator end() noexcept;
-
const_iterator end() const noexcept;
-
const_iterator cend() const noexcept;
Effects: Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.
Complexity: Constant.
-
reverse_iterator rbegin() noexcept;
-
const_reverse_iterator rbegin() const noexcept;
-
const_reverse_iterator crbegin() const noexcept;
Effects: Returns a reverse iterator to the first element of the reversed container. It corresponds to the last element of the non-reversed container. If the container is empty, the returned iterator is equal to
rend()
.Complexity: Constant.
-
reverse_iterator rend() noexcept;
-
const_reverse_iterator rend() const noexcept;
-
const_reverse_iterator crend() const noexcept;
Effects: Returns a reverse iterator to the element following the last element of the reversed container. It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behavior.
Complexity: Constant.
-
iterator nth(size_type pos) noexcept;
-
const_iterator nth(size_type pos) const noexcept;
Preconditions:
pos <= size()
Effects: Returns an iterator to the element at position
pos
.If
pos == size()
, the returned iterator is equal toend()
.Complexity: Constant.
-
size_type index_of(const_iterator pos) const noexcept;
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Returns position of the element pointed by iterator
pos
, i.e.std::distance(begin(), pos)
.If
pos == end()
, the returned value is equal tosize()
.Complexity: Constant.
-
bool empty() const noexcept;
Effects: Returns
true
if the container has no elements, i.e. whetherbegin() == end()
.Complexity: Constant.
-
size_type size() const noexcept;
Effects: Returns the number of elements in the container, i.e.
std::distance(begin(), end())
.Complexity: Constant.
-
size_type max_size() const noexcept;
Effects: Returns the maximum number of elements the container is able to hold, i.e.
std::distance(begin(), end())
for the largest container.Complexity: Constant.
-
size_type capacity() const noexcept;
Effects: Returns the number of elements that the container has currently allocated space for.
Complexity: Constant.
-
size_type available() const noexcept;
Effects: Returns the number of elements that can be pushed to the front without requiring allocation of additional memory.
Complexity: Constant.
-
size_type available() const noexcept;
Effects: Returns the number of elements that can be pushed to the back without requiring allocation of additional memory.
Complexity: Constant.
-
void reserve_front(size_type new_capacity);
Effects: Ensures that
n
elements can be pushed to the front without requiring allocation of additional memory, wheren
isnew_capacity - size()
. Otherwise, there are no effects.This function does not change size of the container.
If the capacity is changed, all iterators to the elements are invalidated, but references and pointers to elements remain valid. Otherwise, no iterators or references are invalidated.
-
void reserve_back(size_type new_capacity);
Effects: Ensures that
n
elements can be pushed to the back without requiring allocation of additional memory, wheren
isnew_capacity - size()
. Otherwise, there are no effects.This function does not change size of the container.
If the capacity is changed, all iterators to the elements are invalidated, but references and pointers to elements remain valid. Otherwise, no iterators or references are invalidated.
-
void shrink_to_fit();
Effects: Tries to reduce memory usage by freeing unused memory.
This function does not change size of the container.
If the capacity is changed, all iterators to the elements are invalidated, but references and pointers to elements remain valid. Otherwise, no iterators or references are invalidated.
-
reference at(size_type pos);
-
const_reference at(size_type pos) const;
Effects: Returns a reference to the element at specified location
pos
, with bounds checking.Complexity: Constant.
Exceptions:
std::out_of_range
ifpos >= size()
.
-
reference operator[](size_type pos) noexcept;
-
const_reference operator[](size_type pos) const noexcept;
Preconditions:
pos < size()
Effects: Returns a reference to the element at specified location pos. No bounds checking is performed.
Note: This operator never inserts a new element into the container.
Complexity: Constant.
-
reference front() noexcept;
-
const_reference front() const noexcept;
Preconditions:
!empty()
Effects: Returns a reference to the first element in the container.
Complexity: Constant.
-
reference back() noexcept;
-
const_reference back() const noexcept;
Preconditions:
!empty()
Effects: Returns a reference to the last element in the container.
Complexity: Constant.
-
void clear() noexcept;
Effects: Erases all elements from the container. After this call,
size()
returns zero andcapacity()
remains unchanged.Complexity: Linear in
size()
.
-
template <typename... Args> iterator emplace(const_iterator pos, Args&&... args);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts a new element into the container at position
pos
.New element is constructed as
value_type(std::forward<Args>(args)...)
.args...
may directly or indirectly refer to a value in the container.Returns: Iterator to the inserted element.
Complexity: Constant plus linear in
std::min(std::distance(begin(), pos), std::distance(pos, end()))
.
-
iterator insert(const_iterator pos, const T& value);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts copy of
value
at positionpos
.Returns: Iterator to the inserted element.
Complexity: Constant plus linear in
std::min(std::distance(begin(), pos), std::distance(pos, end()))
. -
iterator insert(const_iterator pos, T&& value);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts
value
using move semantics at positionpos
.Returns: Iterator to the inserted element.
Complexity: Constant plus linear in
std::min(std::distance(begin(), pos), std::distance(pos, end()))
. -
iterator insert(const_iterator pos, size_type n, const T& value);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts
n
copies ofvalue
before positionpos
.Returns: Iterator to the first element inserted, or
pos
ifn == 0
.Complexity: Linear in
n
plus linear instd::min(std::distance(begin(), pos), std::distance(pos, end()))
. -
template <typename InputIt> iterator insert(const_iterator pos, InputIt first, InputIt last);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts elements from the range
[first, last)
before positionpos
.Note: This overload participates in overload resolution only if
InputIt
satisfies requirements of LegacyInputIterator.Note: The behavior is undefined if either
first
orlast
is an iterator into*this
.Returns: Iterator to the first element inserted, or
pos
iffirst == last
.Complexity: Linear in
std::distance(first, last)
plus linear instd::min(std::distance(begin(), pos), std::distance(pos, end()))
. -
iterator insert(const_iterator pos, std::initializer_list<T> ilist);
Preconditions:
cbegin() <= pos && pos <= cend()
Effects: Inserts elements from initializer list
ilist
before positionpos
.Returns: Iterator to the first element inserted, or
pos
ifilist
is empty.Complexity: Linear in
ilist.size()
plus linear instd::min(std::distance(begin(), pos), std::distance(pos, end()))
.
-
template <typename... Args> reference emplace_front(Args&&... args);
Effects: Inserts a new element at the beginning of container.
New element is constructed as
value_type(std::forward<Args>(args)...)
.Returns: Reference to the inserted element.
Complexity: Constant.
-
template <typename... Args> reference emplace_back(Args&&... args);
Effects: Inserts a new element at the end of container.
New element is constructed as
value_type(std::forward<Args>(args)...)
.Returns: Reference to the inserted element.
Complexity: Constant.
-
void push_front(const T& value);
Effects: Inserts copy of
value
at the beginning of container.Complexity: Constant.
-
void push_front(T&& value);
Effects: Inserts
value
using move semantics at the beginning of container.Complexity: Constant.
-
void push_back(const T& value);
Effects: Inserts copy of
value
at the end of container.Complexity: Constant.
-
void push_back(T&& value);
Effects: Inserts
value
using move semantics at the end of container.Complexity: Constant.
-
void pop_front();
Preconditions:
!empty()
Effects: Removes the first element of the container.
Complexity: Constant.
-
void pop_back();
Preconditions:
!empty()
Effects: Removes the last element of the container.
Complexity: Constant.
-
iterator erase(const_iterator pos);
Preconditions:
cbegin() <= pos && pos < cend()
Effects: Removes the element at
pos
.Returns: Iterator following the last removed element.
If
pos
refers to the last element, then theend()
iterator is returned. -
iterator erase(const_iterator first, const_iterator last);
Preconditions:
cbegin() <= first && first <= last && last <= cend()
Effects: Removes the elements in the range
[first, last)
.Returns: Iterator following the last removed element.
If
last == end()
prior to removal, then the updatedend()
iterator is returned.If
[first, last)
is an empty range, thenlast
is returned.
-
void resize(size_type n);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the lastsize() - n
elements are removed. - If the
size() < n
, additional default-constructed elements are inserted into container. Additional elements could be inserted both at the beginning and at the end of container.
- If the
-
void resize(size_type n, const T& value);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the lastsize() - n
elements are removed. - If the
size() < n
, additional copies ofvalue
are inserted into container. Additional elements could be inserted both at the beginning and at the end of container.
- If the
-
void resize_front(size_type n);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the firstsize() - n
elements are removed. - If the
size() < n
, additional default-constructed elements are inserted at the beginning of container.
- If the
-
void resize_front(size_type n, const T& value);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the firstsize() - n
elements are removed. - If the
size() < n
, additional copies ofvalue
are inserted at the beginning of container.
- If the
-
void resize_back(size_type n);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the lastsize() - n
elements are removed. - If the
size() < n
, additional default-constructed elements are inserted at the end of container.
- If the
-
void resize_back(size_type n, const T& value);
Effects: Resizes the container to contain
n
elements.- If the
size() > n
, the lastsize() - n
elements are removed. - If the
size() < n
, additional copies ofvalue
are inserted at the end of container.
- If the
-
void swap(segmented_devector& other) noexcept;
Preconditions:
allocator_traits::propagate_on_container_swap::value || get_allocator() == other.get_allocator()
Effects: Exchanges the contents of the container with those of
other
.Complexity: Constant.
-
template <typename T, std::size_t N, typename A> bool operator== ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Checks if the contents of
x
andy
are equal.The contents of
x
andy
are equal if the following conditions hold:x.size() == y.size()
- Each element in
x
compares equal with the element iny
at the same position.
Returns:
true
if the contents of thex
andy
are equal,false
otherwise.Complexity: Constant if
x
andy
are of different size, otherwise linear in the size of the container.
-
template <typename T, std::size_t N, typename A> bool operator!= ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Checks if the contents of
x
andy
are equal.For details see
operator==
.Returns:
true
if the contents of thex
andy
are not equal,false
otherwise.Complexity: Constant if
x
andy
are of different size, otherwise linear in the size of the container.
-
template <typename T, std::size_t N, typename A> bool operator< ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
.Returns:
true
if the contents of thex
are lexicographically less than the contents ofy
,false
otherwise.Complexity: Linear in the size of the container.
-
template <typename T, std::size_t N, typename A> bool operator> ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
.Returns:
true
if the contents of thex
are lexicographically greater than the contents ofy
,false
otherwise.Complexity: Linear in the size of the container.
-
template <typename T, std::size_t N, typename A> bool operator<= ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
.Returns:
true
if the contents of thex
are lexicographically less than or equal to the contents ofy
,false
otherwise.Complexity: Linear in the size of the container.
-
template <typename T, std::size_t N, typename A> bool operator>= ( const segmented_devector<T, N, A>& x, const segmented_devector<T, N, A>& y );
Effects: Compares the contents of
x
andy
lexicographically. The comparison is performed by a functionstd::lexicographical_compare
.Returns:
true
if the contents of thex
are lexicographically greater than or equal to the contents ofy
,false
otherwise.Complexity: Linear in the size of the container.
-
template <typename T, std::size_t N, typename A> void swap ( segmented_devector<T, N, A>& x, segmented_devector<T, N, A>& y );
Effects: Swaps the contents of
x
andy
. Callsx.swap(y)
.
-
template <typename T, std::size_t N, typename A, typename U> typename segmented_devector<T, N, A>::size_type erase(segmented_devector<T, N, A>& c, const U& value);
Effects: Erases all elements that compare equal to
value
from the container.Returns: The number of erased elements.
Complexity: Linear.
-
template <typename T, std::size_t N, typename A, typename Predicate> typename segmented_devector<T, N, A>::size_type erase_if(segmented_devector<T, N, A>& c, Predicate pred);
Effects: Erases all elements that satisfy the predicate
pred
from the container.pred
is unary predicate which returnstrue
if the element should be removed.Returns: The number of erased elements.
Complexity: Linear.
End of document.