19#if __has_include(<cereal/types/array.hpp>)
20# include <cereal/types/array.hpp>
43template <
typename value_type_,
size_t capacity_>
48 static constexpr bool is_noexcept = std::is_nothrow_copy_constructible_v<value_type_>;
66 using allocator_type = void;
91 data_{array}, sz{capacity_}
95 template <
size_t capacity2>
99 static_assert(capacity2 <= capacity_,
"You can only initialize from array that has smaller or equal capacity.");
115 template <
size_t capacity2>
118 static_assert(capacity2 <= capacity_,
"You can only initialize from array that has smaller or equal capacity.");
133 template <
typename... other_value_type>
134 requires(std::same_as<value_type, other_value_type> && ...)
135 constexpr
small_vector(other_value_type... args) noexcept(is_noexcept) :
136 data_{args...}, sz{
sizeof...(other_value_type)}
138 static_assert(
sizeof...(other_value_type) <= capacity_,
"Value list must not exceed the capacity.");
156 template <std::forward_iterator begin_it_type,
typename end_it_type>
157 requires(std::sentinel_for<end_it_type, begin_it_type> &&
158 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
177 template <meta::different_from<small_vector> other_range_t>
178 requires(std::ranges::input_range<other_range_t>)
179 explicit constexpr small_vector(other_range_t && range)
noexcept(is_noexcept) :
262 template <std::ranges::input_range other_range_t>
263 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
264 constexpr void assign(other_range_t && range)
noexcept(is_noexcept)
284 template <std::forward_iterator begin_it_type,
typename end_it_type>
285 requires(std::sentinel_for<end_it_type, begin_it_type> &&
286 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
287 constexpr void assign(begin_it_type begin_it, end_it_type end_it)
noexcept(is_noexcept)
338 throw std::out_of_range{
"Trying to access element behind the last in small_vector."};
348 throw std::out_of_range{
"Trying to access element behind the last in small_vector."};
423 return (*
this)[
size() - 1];
430 return (*
this)[
size() - 1];
454 constexpr bool empty() const noexcept {
return size() == 0; }
524 constexpr void clear() noexcept { sz = 0; }
543 return insert(pos, 1, value);
588 template <std::forward_iterator begin_it_type,
typename end_it_type>
589 requires(std::sentinel_for<end_it_type, begin_it_type> &&
590 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
593 auto const pos_as_num = std::ranges::distance(
cbegin(), pos);
594 auto const length = std::ranges::distance(begin_it, end_it);
596 assert(pos_as_num + length <=
capacity());
601 for (
size_type i = sz + length - 1; i > pos_as_num + length - 1; --i)
602 data_[i] = data_[i - length];
606 return begin() + pos_as_num;
626 return insert(pos, ilist.begin(), ilist.end());
649 if (begin_it >= end_it)
650 return begin() + std::ranges::distance(
cbegin(), end_it);
652 size_type const length = std::ranges::distance(begin_it, end_it);
653 auto out_it =
begin() + std::ranges::distance(
cbegin(), begin_it);
655 while (end_it !=
cend())
656 *(out_it++) = *(end_it++);
659 return begin() + std::ranges::distance(
cbegin(), begin_it);
697 assert(sz < capacity_);
737 assert(count <= capacity_);
747 assert(count <= capacity_);
748 for (
size_t i = sz; i < count; ++i)
771 rhs.data_ = tmp.data_;
804 template <
size_t cap2>
811 template <
size_t cap2>
814 for (
size_t i = 0; i <
std::min(lhs.size(), rhs.size()); ++i)
817 else if (lhs[i] < rhs[i])
819 return lhs.size() < rhs.size();
823 template <
size_t cap2>
826 for (
size_t i = 0; i <
std::min(lhs.size(), rhs.size()); ++i)
829 else if (lhs[i] > rhs[i])
831 return lhs.size() > rhs.size();
835 template <
size_t cap2>
842 template <
size_t cap2>
865 template <
typename archive_t>
866 void serialize(archive_t & archive)
879template <
size_t capacity2,
typename value_type>
A constexpr vector implementation with dynamic size at compile time.
Definition: small_vector.hpp:45
constexpr value_type const * data() const noexcept
Direct access to the underlying array.
Definition: small_vector.hpp:437
constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept)
Inserts elements from range [begin_it, end_it) before position in the container.
Definition: small_vector.hpp:591
constexpr void swap(small_vector &&rhs) noexcept(is_noexcept)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: small_vector.hpp:776
reference at(size_type const i)
Return the i-th element.
Definition: small_vector.hpp:334
constexpr void reserve(size_type) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: small_vector.hpp:499
friend constexpr void swap(small_vector &lhs, small_vector &rhs) noexcept(is_noexcept)
Swap contents with another instance.
Definition: small_vector.hpp:795
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:313
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition: small_vector.hpp:680
value_type & reference
The reference type.
Definition: small_vector.hpp:55
constexpr reference back() noexcept
Return the last element.
Definition: small_vector.hpp:420
constexpr iterator end() noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:307
value_type_ value_type
The value_type type.
Definition: small_vector.hpp:54
constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept(is_noexcept)
Inserts count copies of value before position in the container.
Definition: small_vector.hpp:562
constexpr const_reference back() const noexcept
Return the last element.
Definition: small_vector.hpp:427
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept)
Assign from pair of iterators.
Definition: small_vector.hpp:287
constexpr const_iterator end() const noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:310
constexpr void assign(std::initializer_list< value_type > ilist) noexcept(is_noexcept)
Assign from std::initializer_list.
Definition: small_vector.hpp:225
constexpr small_vector(other_range_t &&range) noexcept(is_noexcept)
Construct from a different range.
Definition: small_vector.hpp:179
friend constexpr void swap(small_vector &&lhs, small_vector &&rhs) noexcept(is_noexcept)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: small_vector.hpp:798
friend constexpr bool operator>(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:824
constexpr value_type * data() noexcept
Direct access to the underlying array.
Definition: small_vector.hpp:434
constexpr iterator insert(const_iterator pos, std::initializer_list< value_type > const &ilist) noexcept(is_noexcept)
Inserts elements from initializer list before position in the container.
Definition: small_vector.hpp:624
constexpr iterator insert(const_iterator pos, value_type const value) noexcept(is_noexcept)
Inserts value before position in the container.
Definition: small_vector.hpp:541
meta::detail::min_viable_uint_t< capacity_ > size_type
The size_type type.
Definition: small_vector.hpp:60
constexpr small_vector & operator=(std::initializer_list< value_type > ilist) noexcept(is_noexcept)
Assign from std::initializer_list.
Definition: small_vector.hpp:208
constexpr void resize(size_type const count, value_type const value) noexcept
Resizes the container to contain count elements.
Definition: small_vector.hpp:745
ptrdiff_t difference_type
The difference_type type.
Definition: small_vector.hpp:59
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_vector.hpp:735
constexpr const_iterator cbegin() const noexcept
Returns the begin iterator of the vector.
Definition: small_vector.hpp:304
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition: small_vector.hpp:716
constexpr small_vector(value_type const (&array)[capacity2]) noexcept(is_noexcept)
Construct from a (smaller or equally sized) built in array over the same value type.
Definition: small_vector.hpp:116
constexpr reference operator[](size_type const i) noexcept
Return the i-th element.
Definition: small_vector.hpp:368
value_type const * const_iterator
The const_iterator type.
Definition: small_vector.hpp:58
constexpr small_vector(size_type n, value_type value) noexcept(is_noexcept)
Construct with n times value.
Definition: small_vector.hpp:195
friend constexpr bool operator==(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:805
constexpr const_reference front() const noexcept
Return the first element. Calling front on an empty container is undefined.
Definition: small_vector.hpp:401
constexpr const_iterator begin() const noexcept
Returns the begin iterator of the vector.
Definition: small_vector.hpp:301
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition: small_vector.hpp:695
value_type const & const_reference
The const_reference type.
Definition: small_vector.hpp:56
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: small_vector.hpp:505
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: small_vector.hpp:467
constexpr void assign(size_type const count, value_type const value) noexcept(is_noexcept)
Assign with count times value.
Definition: small_vector.hpp:242
constexpr const_reference operator[](size_type const i) const noexcept
Return the i-th element.
Definition: small_vector.hpp:375
constexpr void swap(small_vector &rhs) noexcept(is_noexcept)
Swap contents with another instance.
Definition: small_vector.hpp:764
constexpr void clear() noexcept
Removes all elements from the container.
Definition: small_vector.hpp:524
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition: small_vector.hpp:647
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: small_vector.hpp:454
friend constexpr bool operator<(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:812
friend constexpr bool operator<=(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:836
friend constexpr bool operator>=(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:843
constexpr size_type capacity() const noexcept
Returns the number of elements that the container is able to hold and resolves to capacity_.
Definition: small_vector.hpp:496
constexpr void assign(other_range_t &&range) noexcept(is_noexcept)
Assign from a different range.
Definition: small_vector.hpp:264
const_reference at(size_type const i) const
Return the i-th element.
Definition: small_vector.hpp:344
constexpr iterator begin() noexcept
Returns the begin iterator of the vector.
Definition: small_vector.hpp:298
constexpr size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold and resolves to capacity_.
Definition: small_vector.hpp:483
value_type * iterator
The iterator type.
Definition: small_vector.hpp:57
constexpr small_vector() noexcept=default
Defaulted.
constexpr small_vector(begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept)
Construct from two iterators.
Definition: small_vector.hpp:159
constexpr reference front() noexcept
Return the first element. Calling front on an empty container is undefined.
Definition: small_vector.hpp:394
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:98
Provides metaprogramming utilities for integer types.
The ranges module's namespace.
Provides bio::views::repeat_n.
Provides various traits to inspect templates.