23#ifndef GUL17_SMALLVECTOR_H_ 
   24#define GUL17_SMALLVECTOR_H_ 
   29#include <initializer_list> 
  269template <
typename ElementT, 
size_t in_capacity>
 
  328        static_assert(std::is_default_constructible<ValueType>::value,
 
  329            "SmallVector: Element type is not default-constructible");
 
 
  366             typename = std::enable_if_t<not std::is_integral<InputIterator>::value>>
 
  369        fill_empty_vector_with_copied_range(first, last);
 
 
  381        noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
 
  383        static_assert(std::is_copy_constructible<ValueType>::value == 
true,
 
  384            "SmallVector: Element type is not copy-constructible");
 
  385        fill_empty_vector_with_copied_range(
other.cbegin(), 
other.cend());
 
 
  404        noexcept(std::is_nothrow_move_constructible<ValueType>::value)
 
  406        move_or_copy_all_elements_from(std::move(
other));
 
 
  418        fill_empty_vector_with_copied_range(
init.begin(), 
init.end());
 
 
  426        if (is_storage_allocated())
 
 
  463        typename = std::enable_if_t<not std::is_integral<InputIterator>::value>>
 
  467        fill_empty_vector_with_copied_range(first, last);
 
 
  483        std::uninitialized_copy(
init.begin(), 
init.end(), 
data());
 
 
  494            throw std::out_of_range(
cat(
"Index out of range: ", 
idx, 
" >= ", size_));
 
 
  502            throw std::out_of_range(
cat(
"Index out of range: ", 
idx, 
" >= ", size_));
 
 
  512        return *(data_end() - 1);
 
 
  521        return *(data_end() - 1);
 
 
  572        destroy_range(
data(), data_end());
 
 
  584        return std::make_reverse_iterator(
end());
 
 
  595        return std::make_reverse_iterator(
begin());
 
 
  604        return reinterpret_cast<ValueType*
>(data_ptr_);
 
 
  613        return reinterpret_cast<const ValueType*
>(data_ptr_);
 
 
  647            return data_end() - 1;
 
  652        return insert_single_value(
pos, std::move(
v));
 
 
  675        if (size_ == capacity_)
 
  678        ::new(
static_cast<void*
>(data_end()))
 
 
  785        return insert_single_value(
pos, 
value);
 
 
  799        return insert_single_value(
pos, std::move(
value));
 
 
  851             typename = std::enable_if_t<not std::is_integral<InputIterator>::value>>
 
  866        copy_range_into_uninitialized_cells(size_, first + 
num_assignable, last);
 
 
  899        return std::numeric_limits<SizeType>::max();
 
 
  910        noexcept(std::is_nothrow_copy_assignable<ValueType>::value)
 
  917            size_ = 
other.size();
 
 
  937        noexcept(std::is_nothrow_move_constructible<ValueType>::value)
 
  942            if (is_storage_allocated())
 
  944            move_or_copy_all_elements_from(std::move(
other));
 
 
  969        return std::equal(
lhs.cbegin(), 
lhs.cend(), 
rhs.cbegin(), 
rhs.cend());
 
 
 1003        auto p = data_end();
 
 
 1018        if (size_ == capacity_)
 
 
 1036        if (size_ == capacity_)
 
 
 1052        return std::make_reverse_iterator(
end());
 
 
 1062        return std::make_reverse_iterator(
begin());
 
 
 1080        const auto d_end = data_end();
 
 1085        if (is_storage_allocated())
 
 
 1109        static_assert(std::is_default_constructible<ValueType>::value,
 
 1110            "SmallVector: For using resize(), element type must be default-constructible");
 
 1119            fill_uninitialized_cells_with_default_constructed_elements(size_,
 
 
 1165        auto new_memory = std::unique_ptr<AlignedStorage[]>{};
 
 1174        const auto d_end = data_end();
 
 1179        if (is_storage_allocated())
 
 
 1198        if (is_storage_allocated())
 
 1200            if (
other.is_storage_allocated())
 
 1201                swap_heap_with_heap(*
this, 
other);
 
 1203                swap_heap_with_internal(*
this, 
other);
 
 1207            if (
other.is_storage_allocated())
 
 1208                swap_heap_with_internal(
other, *
this);
 
 1210                swap_internal_with_internal(*
this, 
other);
 
 
 1215    using AlignedStorage =
 
 1222    std::array<AlignedStorage, in_capacity> internal_array_;
 
 1225    AlignedStorage* data_ptr_{ internal_array_.data() };
 
 1245    template<
class InputIterator>
 
 1253            for (
auto it = first; 
it != last; ++
it)
 
 1286        return reinterpret_cast<ValueType*
>(data_ptr_) + size_;
 
 1292        return reinterpret_cast<const ValueType*
>(data_ptr_) + size_;
 
 1323    template<
typename InputIterator>
 
 1329        copy_range_into_uninitialized_cells(0
u, first, last);
 
 1356    void fill_uninitialized_cells_with_default_constructed_elements(
SizeType pos,
 
 1386        const auto remaining_space = std::numeric_limits<SizeType>::max() - capacity_;
 
 1389            throw std::length_error(
"Max. capacity reached");
 
 1401    template <
typename T>
 
 1407            return begin() + size_ - 1;
 
 1412        if (size_ == capacity_)
 
 1433        return data_ptr_ != internal_array_.data();
 
 1493        noexcept(std::is_nothrow_move_constructible<ValueType>::value)
 
 1496        if (
other.is_storage_allocated())
 
 1498            data_ptr_ = 
other.data_ptr_;    
other.data_ptr_ = 
other.internal_array_.data();
 
 1499            capacity_ = 
other.capacity_;    
other.capacity_ = 
other.inner_capacity();
 
 1504            data_ptr_ = internal_array_.data();
 
 1507            size_ = 
other.size();
 
 1519        std::swap(
a.data_ptr_, 
b.data_ptr_);
 
 1520        std::swap(
a.capacity_, 
b.capacity_);
 
 1521        std::swap(
a.size_, 
b.size_);
 
 1532        uninitialized_move_or_copy(
b.begin(), 
b.end(),
 
 1533            reinterpret_cast<ValueType*
>(
a.internal_array_.data()));
 
 1534        destroy_range(
b.begin(), 
b.end());
 
 1536        b.data_ptr_ = 
a.data_ptr_;
 
 1537        a.data_ptr_ = 
a.internal_array_.data();
 
 1539        std::swap(
a.capacity_, 
b.capacity_);
 
 1540        std::swap(
a.size_, 
b.size_);
 
 1550        if (
a.size_ <= 
b.size_)
 
 1553                std::swap(
a.data()[
i], 
b.data()[
i]);
 
 1555            uninitialized_move_or_copy(
b.begin() + 
a.size_, 
b.end(), 
a.begin() + 
a.size_);
 
 1556            destroy_range(
b.begin() + 
a.size_, 
b.end());
 
 1561                std::swap(
a.data()[
i], 
b.data()[
i]);
 
 1563            uninitialized_move_or_copy(
a.begin() + 
b.size_, 
a.end(), 
b.begin() + 
b.size_);
 
 1564            destroy_range(
a.begin() + 
b.size_, 
a.end());
 
 1567        std::swap(
a.size_, 
b.size_);
 
 1574    template <
typename T>
 
 1575    static typename std::enable_if_t<not std::is_nothrow_move_constructible<T>::value>
 
 1603    template <
typename T>
 
 1604    static typename std::enable_if_t<std::is_nothrow_move_constructible<T>::value>
 
 1620    template <
typename T>
 
 1621    static typename std::enable_if_t<std::is_nothrow_move_constructible<T>::value>
 
 1629    template <
typename T>
 
 1630    static typename std::enable_if_t<not std::is_nothrow_move_constructible<T>::value 
and 
 1631                                     std::is_copy_constructible<T>::value>
 
 1639    template <
typename T>
 
 1640    static typename std::enable_if_t<not std::is_nothrow_move_constructible<T>::value
 
 1641                                     and not std::is_copy_constructible<T>::value>
 
 
 1656template<
typename ElementT, 
size_t in_capacity>
 
Declaration of the overload set for cat() and of the associated class ConvertingStringView.
 
A resizable container with contiguous storage that can hold a specified number of elements without al...
Definition SmallVector.h:271
 
constexpr Iterator begin() noexcept
Return an iterator to the first element of the vector.
Definition SmallVector.h:528
 
void assign(SizeType num_elements, const ValueType &value)
Fill the vector with a certain number of copies of the given value after clearing all previous conten...
Definition SmallVector.h:437
 
Iterator emplace(ConstIterator pos, ArgumentTypes &&... arguments)
Construct an additional element at an arbitrary position in the vector.
Definition SmallVector.h:642
 
SmallVector & operator=(const SmallVector &other) noexcept(std::is_nothrow_copy_assignable< ValueType >::value)
Copy assignment operator: Copy all elements from another SmallVector after clearing all previous cont...
Definition SmallVector.h:909
 
std::reverse_iterator< ConstIterator > ConstReverseIterator
Iterator to a const element in reversed container.
Definition SmallVector.h:306
 
SmallVector(std::initializer_list< ValueType > init)
Construct a SmallVector that is filled with copies of the elements from a given initializer list.
Definition SmallVector.h:416
 
constexpr Reference operator[](SizeType idx)
Return a reference to the element at the specified index.
Definition SmallVector.h:985
 
constexpr ConstIterator cbegin() const noexcept
Return a const iterator to the first element of the vector.
Definition SmallVector.h:552
 
friend bool operator!=(const SmallVector &lhs, const SmallVector &rhs)
Inequality operator: Return true if both vectors have a different size() or at least one different el...
Definition SmallVector.h:979
 
void clear() noexcept
Erase all elements from the container without changing its capacity.
Definition SmallVector.h:570
 
SmallVector(SizeType num_elements, const ValueType &value)
Construct a SmallVector that is filled with a certain number of copies of the given value.
Definition SmallVector.h:344
 
ReverseIterator rbegin() noexcept
Return a reverse iterator to the first element of the reversed vector (which is the last element of t...
Definition SmallVector.h:1050
 
constexpr Reference at(SizeType idx)
Return a reference to the element at the specified index with bounds-checking.
Definition SmallVector.h:491
 
Reference reference
Reference to an element.
Definition SmallVector.h:288
 
constexpr ConstReference operator[](SizeType idx) const
Return a const reference to the element at the specified index.
Definition SmallVector.h:991
 
constexpr Reference back() noexcept
Return a reference to the last element in the vector.
Definition SmallVector.h:510
 
ValueType value_type
Type of the elements in the underlying container.
Definition SmallVector.h:276
 
Iterator insert(ConstIterator pos, SizeType num_elements, const ValueType &value)
Insert a number of copies of the given value before the indicated position.
Definition SmallVector.h:811
 
ConstReverseIterator crbegin() noexcept
Return a const reverse iterator to the first element of the reversed vector (which is the last elemen...
Definition SmallVector.h:582
 
friend bool operator==(const SmallVector &lhs, const SmallVector &rhs)
Equality operator: Return true if both vectors have the same size() and the same elements.
Definition SmallVector.h:967
 
void assign(InputIterator first, InputIterator last)
Fill the vector with copies of elements from the given range.
Definition SmallVector.h:464
 
ValueType * Iterator
Iterator to an element.
Definition SmallVector.h:294
 
void assign(std::initializer_list< ValueType > init)
Assign the elements of an initializer list to this vector after clearing all previous contents.
Definition SmallVector.h:477
 
Iterator insert(ConstIterator pos, std::initializer_list< ValueType > init)
Insert elements from an initializer list before the indicated position.
Definition SmallVector.h:886
 
void shrink_to_fit()
Reduce the capacity as far as possible while retaining all stored elements.
Definition SmallVector.h:1156
 
ElementT ValueType
Type of the elements in the underlying container.
Definition SmallVector.h:274
 
constexpr ConstIterator cend() const noexcept
Return a const iterator pointing past the last element of the vector.
Definition SmallVector.h:561
 
const ValueType & ConstReference
Reference to a const element.
Definition SmallVector.h:290
 
Iterator iterator
Iterator to an element.
Definition SmallVector.h:296
 
SmallVector(SmallVector &&other) noexcept(std::is_nothrow_move_constructible< ValueType >::value)
Move constructor: Create a SmallVector from the contents of another one with the same inner capacity ...
Definition SmallVector.h:403
 
~SmallVector()
Destructor: Destroys all stored elements and frees all allocated memory.
Definition SmallVector.h:422
 
void swap(SmallVector &other)
Exchange the contents of this SmallVector with those of another one.
Definition SmallVector.h:1196
 
void reserve(SizeType new_capacity)
Increase the capacity of the vector to the specified size.
Definition SmallVector.h:1073
 
std::ptrdiff_t DifferenceType
Signed integer type for the difference of two iterators.
Definition SmallVector.h:282
 
constexpr ConstReference front() const noexcept
Return a const reference to the first element in the vector.
Definition SmallVector.h:763
 
constexpr ConstIterator begin() const noexcept
Return a const iterator to the first element of the vector.
Definition SmallVector.h:537
 
SmallVector() noexcept=default
Construct an empty SmallVector.
 
ConstReference const_reference
Reference to a const element.
Definition SmallVector.h:292
 
Iterator erase(ConstIterator pos)
Erase a single element from the vector, moving elements behind it forward.
Definition SmallVector.h:718
 
constexpr ValueType * data() noexcept
Return a pointer to the contiguous data storage of the vector.
Definition SmallVector.h:602
 
SmallVector & operator=(std::initializer_list< ValueType > init)
Assign the elements of an initializer list to this vector after clearing all previous contents.
Definition SmallVector.h:954
 
SmallVector(InputIterator first, InputIterator last)
Construct a SmallVector that is filled with copies of elements from the given range.
Definition SmallVector.h:367
 
ReverseIterator rend() noexcept
Return a reverse iterator pointing past the last element of the reversed vector.
Definition SmallVector.h:1060
 
ValueType & Reference
Reference to an element.
Definition SmallVector.h:286
 
std::uint32_t SizeType
Unsigned integer type for indexing, number of elements, capacity.
Definition SmallVector.h:278
 
SizeType size_type
Unsigned integer type for indexing, number of elements, capacity.
Definition SmallVector.h:280
 
constexpr ConstReference back() const noexcept
Return a const reference to the last element in the vector.
Definition SmallVector.h:519
 
constexpr Reference front() noexcept
Return a reference to the first element in the vector.
Definition SmallVector.h:754
 
constexpr const ValueType * data() const noexcept
Return a pointer to the contiguous data storage of the vector.
Definition SmallVector.h:611
 
Iterator insert(ConstIterator pos, ValueType &&value)
Insert a single element before the indicated position.
Definition SmallVector.h:797
 
SmallVector(const SmallVector &other) noexcept(std::is_nothrow_copy_constructible< ValueType >::value)
Create a copy of another SmallVector with the same inner capacity.
Definition SmallVector.h:380
 
constexpr bool empty() const noexcept
Determine if the vector is empty.
Definition SmallVector.h:687
 
Iterator insert(ConstIterator pos, const ValueType &value)
Insert a single element before the indicated position.
Definition SmallVector.h:783
 
void resize(SizeType num_elements)
Change the number of elements in the container.
Definition SmallVector.h:1107
 
constexpr SizeType capacity() const noexcept
Return the number of elements that can currently be stored in this vector without having to allocate ...
Definition SmallVector.h:546
 
SmallVector & operator=(SmallVector &&other) noexcept(std::is_nothrow_move_constructible< ValueType >::value)
Move assignment operator: Assign all of the elements from another vector to this one using move seman...
Definition SmallVector.h:936
 
constexpr ConstIterator end() const noexcept
Return a const iterator pointing past the last element of the vector.
Definition SmallVector.h:702
 
constexpr SizeType inner_capacity() const noexcept
Return the number of elements this SmallVector can hold internally without having to allocate storage...
Definition SmallVector.h:772
 
Reference emplace_back(ArgumentTypes &&... arguments)
Construct an additional element at the end of the buffer.
Definition SmallVector.h:673
 
void push_back(ValueType &&value)
Move one element to the end of the buffer.
Definition SmallVector.h:1034
 
Iterator erase(ConstIterator first, ConstIterator last)
Erase a range of elements from the vector, moving elements behind the range forward.
Definition SmallVector.h:736
 
Iterator insert(ConstIterator pos, InputIterator first, InputIterator last)
Insert a range of values before the indicated position.
Definition SmallVector.h:852
 
constexpr SizeType max_size() const noexcept
Return the maximum number of elements that this vector can theoretically hold.
Definition SmallVector.h:897
 
ConstReverseIterator const_reverse_iterator
Iterator to a const element in reversed container.
Definition SmallVector.h:308
 
ConstIterator const_iterator
Iterator to a const element.
Definition SmallVector.h:300
 
constexpr ConstReference at(SizeType idx) const
Return a const reference to the element at the specified index.
Definition SmallVector.h:499
 
void push_back(const ValueType &value)
Copy one element to the end of the buffer.
Definition SmallVector.h:1016
 
void resize(SizeType num_elements, const ValueType &element)
Change the number of elements in the container.
Definition SmallVector.h:1137
 
constexpr SizeType size() const noexcept
Return the number of elements that are currently stored.
Definition SmallVector.h:1187
 
void pop_back()
Remove the last element from the vector.
Definition SmallVector.h:1000
 
DifferenceType difference_type
Signed integer type for the difference of two iterators.
Definition SmallVector.h:284
 
ReverseIterator reverse_iterator
Iterator to an element in reversed container.
Definition SmallVector.h:304
 
std::reverse_iterator< Iterator > ReverseIterator
Iterator to an element in reversed container.
Definition SmallVector.h:302
 
ConstReverseIterator crend() noexcept
Return a const reverse iterator pointing past the last element of the reversed vector.
Definition SmallVector.h:593
 
const ValueType * ConstIterator
Iterator to a const element.
Definition SmallVector.h:298
 
constexpr Iterator end() noexcept
Return an iterator pointing past the last element of the vector.
Definition SmallVector.h:693
 
void swap(SmallVector< ElementT, in_capacity > &a, SmallVector< ElementT, in_capacity > &b)
Exchange the contents of one SmallVector with those of another one.
Definition SmallVector.h:1657
 
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:121
 
std::string cat()
Efficiently concatenate an arbitrary number of strings and numbers.
Definition cat.h:97
 
Definition of macros used internally by GUL.
 
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:26