16 #include <type_traits> 18 #if SEQAN3_WITH_CEREAL 19 #include <cereal/types/array.hpp> 20 #endif // SEQAN3_WITH_CEREAL 46 template <
typename value_type_,
size_t capacity_>
51 static constexpr
bool is_noexcept = std::is_nothrow_copy_constructible_v<value_type_>;
69 using allocator_type = void;
98 template <
size_t capacity2>
102 static_assert(capacity2 <= capacity_,
"You can only initialize from array that has smaller or equal capacity.");
118 template <
size_t capacity2>
122 static_assert(capacity2 <= capacity_,
"You can only initialize from array that has smaller or equal capacity.");
137 template <
typename ...other_value_type>
141 constexpr
small_vector(other_value_type... args) noexcept(is_noexcept) :
142 data_{args...},
sz{
sizeof...(other_value_type)}
144 static_assert(
sizeof...(other_value_type) <= capacity_,
"Value list must not exceed the capacity.");
162 template <std::ForwardIterator begin_it_type, std::Sentinel<begin_it_type> end_it_type>
166 constexpr
small_vector(begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept) :
185 template <std::ranges::InputRange other_range_t>
187 requires !std::is_same_v<remove_cvref_t<other_range_t>,
small_vector>
190 explicit constexpr
small_vector(other_range_t && range) noexcept(is_noexcept) :
277 template <std::ranges::InputRange other_range_t>
281 constexpr
void assign(other_range_t && range) noexcept(is_noexcept)
301 template <std::ForwardIterator begin_it_type, std::Sentinel<begin_it_type> end_it_type>
302 constexpr
void assign(begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept)
374 throw std::out_of_range{
"Trying to access element behind the last in small_vector."};
384 throw std::out_of_range{
"Trying to access element behind the last in small_vector."};
459 return (*
this)[
size()-1];
466 return (*
this)[
size()-1];
496 constexpr
bool empty() const noexcept
600 return insert(pos, 1, value);
645 template <std::ForwardIterator begin_it_type, std::Sentinel<begin_it_type> end_it_type>
657 for (
size_type i =
sz + length - 1; i > pos_as_num + length - 1; --i)
662 return begin() + pos_as_num;
682 return insert(pos, ilist.begin(), ilist.end());
705 if (begin_it >= end_it)
711 while (end_it !=
cend())
712 *(out_it++) = *(end_it++);
738 return erase(pos, pos + 1);
756 assert(
sz < capacity_);
796 assert(count <= capacity_);
806 assert(count <= capacity_);
807 for (
size_t i =
sz; i < count; ++i)
830 rhs.data_ = tmp.data_;
869 template <
size_t cap2>
871 requires cap2 <= capacity_
879 template <
size_t cap2>
881 requires cap2 <= capacity_
885 return !(lhs == rhs);
889 template <
size_t cap2>
891 requires cap2 <= capacity_
893 friend constexpr
bool operator<(small_vector const & lhs, small_vector<value_type, cap2>
const & rhs) noexcept
895 for (
size_t i = 0; i <
std::min(lhs.size(), rhs.size()); ++i)
898 else if (lhs[i] < rhs[i])
900 return lhs.size() < rhs.size();
904 template <
size_t cap2>
906 requires cap2 <= capacity_
910 for (
size_t i = 0; i <
std::min(lhs.size(), rhs.size()); ++i)
913 else if (lhs[i] > rhs[i])
915 return lhs.size() > rhs.size();
919 template <
size_t cap2>
921 requires cap2 <= capacity_
923 friend constexpr
bool operator<=(small_vector const & lhs, small_vector<value_type, cap2>
const & rhs) noexcept
929 template <
size_t cap2>
931 requires cap2 <= capacity_
951 template <CerealArchive archive_t>
952 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
963 template <
size_t capacity2,
typename value_type>
965 small_vector(
const value_type (&array)[capacity2]) -> small_vector<value_type, capacity2>;
::ranges::equal equal
Alias for ranges::equal. Determines if two sets of elements are the same.
Definition: algorithm:54
constexpr reference front() noexcept
Return the first element. Calling front on an empty container is undefined.
Definition: small_vector.hpp:430
value_type const * const_iterator
The const_iterator type.
Definition: small_vector.hpp:61
::ranges::distance distance
Alias for ranges::distance. Returns the number of hops from first to last.
Definition: iterator:321
constexpr reference back() noexcept
Return the last element.
Definition: small_vector.hpp:456
constexpr small_vector(other_range_t &&range) noexcept(is_noexcept)
Construct from a different range.
Definition: small_vector.hpp:190
constexpr const_reference operator[](size_type const i) const noexcept
Return the i-th element.
Definition: small_vector.hpp:411
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition: small_vector.hpp:754
Provides metaprogramming utilities for integer types.
constexpr const_iterator begin() const noexcept
Returns the begin to the string.
Definition: small_vector.hpp:322
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition: small_vector.hpp:775
constexpr const_iterator end() const noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:340
value_type * iterator
The iterator type.
Definition: small_vector.hpp:60
Provides seqan3::type_list and auxiliary type traits.
constexpr void resize(size_type const count, value_type const value) noexcept
Resizes the container to contain count elements.
Definition: small_vector.hpp:804
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:547
small_vector(const value_type(&array)[capacity2]) -> small_vector< value_type, capacity2 >
Deducts the size and value type from an built-in array on construction.
SeqAn specific customisations in the standard namespace.
friend constexpr bool operator>(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:908
Provides seqan3::view::take.
constexpr small_vector & operator=(std::initializer_list< value_type > ilist) noexcept(is_noexcept)
Assign from std::initializer_list.
Definition: small_vector.hpp:223
constexpr small_vector() noexcept=default
Defaulted.
friend constexpr void swap(small_vector &lhs, small_vector &rhs) noexcept(is_noexcept)
Swap contents with another instance.
Definition: small_vector.hpp:854
The main SeqAn3 namespace.
constexpr void reserve(size_type) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: small_vector.hpp:553
constexpr void swap(small_vector &rhs) noexcept(is_noexcept)
Swap contents with another instance.
Definition: small_vector.hpp:823
constexpr void assign(other_range_t &&range) noexcept(is_noexcept)
Assign from a different range.
Definition: small_vector.hpp:281
constexpr void resize(size_type const count) noexcept
Resizes the container to contain count elements.
Definition: small_vector.hpp:794
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:346
constexpr iterator end() noexcept
Returns iterator past the end of the vector.
Definition: small_vector.hpp:334
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:649
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:119
constexpr void swap(small_vector &&rhs) noexcept(is_noexcept)
Definition: small_vector.hpp:835
const_reference at(size_type const i) const
Return the i-th element.
Definition: small_vector.hpp:380
constexpr reference operator[](size_type const i) noexcept
Return the i-th element.
Definition: small_vector.hpp:404
constexpr value_type * data() noexcept
Direct access to the underlying array.
Definition: small_vector.hpp:470
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:680
Provides seqan3::view::repeat_n.
constexpr iterator begin() noexcept
Returns the begin to the string.
Definition: small_vector.hpp:316
constexpr const_reference back() const noexcept
Return the last element.
Definition: small_vector.hpp:463
ptrdiff_t difference_type
The difference_type type.
Definition: small_vector.hpp:62
Adaptations of concepts from the Ranges TS.
constexpr void assign(size_type const count, value_type const value) noexcept(is_noexcept)
Assign with count times value.
Definition: small_vector.hpp:257
friend constexpr bool operator!=(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:883
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: small_vector.hpp:559
size_type sz
The size of the actual contained data_.
Definition: small_vector.hpp:943
Adaptions of concepts from the Cereal library.
constexpr small_vector(begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept)
Construct from two iterators.
Definition: small_vector.hpp:166
::ranges::copy copy
Alias for ranges::copy. Copies a range of elements to a new location.
Definition: algorithm:44
friend constexpr bool operator>=(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:933
const value_type & const_reference
The const_reference type.
Definition: small_vector.hpp:59
A constexpr vector implementation with dynamic size at compile time.
Definition: small_vector.hpp:47
constexpr value_type const * data() const noexcept
Direct access to the underlying array.
Definition: small_vector.hpp:476
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:302
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: small_vector.hpp:496
The std::Constructible concept specifies that a variable of type T can be initialized with the given ...
constexpr void assign(std::initializer_list< value_type > ilist) noexcept(is_noexcept)
Assign from std::initializer_list.
Definition: small_vector.hpp:240
constexpr small_vector(size_type n, value_type value) noexcept(is_noexcept)
Construct with n times value.
Definition: small_vector.hpp:206
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:619
constexpr const_reference front() const noexcept
Return the first element. Calling front on an empty container is undefined.
Definition: small_vector.hpp:437
constexpr const_iterator cbegin() const noexcept
Returns the begin to the string.
Definition: small_vector.hpp:328
Adaptations of algorithms from the Ranges TS.
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:531
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition: small_vector.hpp:736
value_type & reference
The reference type.
Definition: small_vector.hpp:58
friend constexpr bool operator==(small_vector const &lhs, small_vector< value_type, cap2 > const &rhs) noexcept
Performs element-wise comparison.
Definition: small_vector.hpp:873
reference at(size_type const i)
Return the i-th element.
Definition: small_vector.hpp:370
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:97
typename reference< t >::type reference_t
Shortcut for seqan3::reference (TransformationTrait shortcut).
Definition: pre.hpp:77
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
char value_type
The value_type type.
Definition: small_vector.hpp:57
constexpr iterator insert(const_iterator pos, value_type const value) noexcept(is_noexcept)
Inserts value before position in the container.
Definition: small_vector.hpp:598
constexpr void clear() noexcept
Removes all elements from the container.
Definition: small_vector.hpp:578
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:179
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition: small_vector.hpp:703
friend constexpr void swap(small_vector &&lhs, small_vector &&rhs) noexcept(is_noexcept)
Definition: small_vector.hpp:860
std::array< value_type, capacity_ > data_
Stores the actual data_.
Definition: small_vector.hpp:941
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: small_vector.hpp:512