15 #include <type_traits> 18 #include <range/v3/view/const.hpp> 19 #include <range/v3/view/join.hpp> 20 #include <range/v3/view/repeat_n.hpp> 21 #include <range/v3/view/slice.hpp> 31 #if SEQAN3_WITH_CEREAL 32 #include <cereal/types/vector.hpp> 82 template <
typename inner_type,
85 requires ReservableContainer<std::remove_reference_t<inner_type>> &&
86 ReservableContainer<std::remove_reference_t<data_delimiters_type>> &&
87 std::is_same_v<size_type_t<inner_type>, value_type_t<data_delimiters_type>>
96 data_delimiters_type data_delimiters{0};
117 using iterator = detail::random_access_iterator<concatenated_sequences>;
121 using const_iterator = detail::random_access_iterator<concatenated_sequences const>;
134 using allocator_type = void;
144 template <
typename t>
145 requires (dimension_v<t> == dimension_v<value_type> + 1) &&
146 std::is_same_v<remove_cvref_t<innermost_value_type_t<value_type>>,
148 static constexpr
bool is_compatible_this_aux =
true;
154 template <
typename t>
157 std::is_same_v<remove_cvref_t<t>,
iterator> ||
163 template <
typename t>
165 std::is_same_v<remove_cvref_t<t>,
value_type> ||
166 std::is_same_v<remove_cvref_t<t>,
reference> ||
198 template <std::ranges::InputRange rng_of_rng_type>
201 requires is_compatible_this<rng_of_rng_type>
207 for (
auto && val : rng_of_rng)
209 data_values.insert(data_values.end(), val.begin(), val.end());
210 data_delimiters.push_back(data_delimiters.back() + val.size());
227 template <std::ranges::ForwardRange rng_type>
230 requires is_compatible_value<rng_type>
237 insert(
cend(), count, std::forward<rng_type>(value));
255 template <std::ForwardIterator begin_iterator_type, std::SizedSentinel<begin_iterator_type> end_iterator_type>
258 requires is_compatible_this<begin_iterator_type>
276 template <std::ranges::ForwardRange rng_type = value_type>
279 requires is_compatible_value<rng_type>
297 template <std::ranges::ForwardRange rng_type>
300 requires is_compatible_value<rng_type>
319 template <std::ranges::InputRange rng_of_rng_type>
320 void assign(rng_of_rng_type && rng_of_rng)
322 requires is_compatible_this<rng_of_rng_type>
342 template <
typename rng_type>
366 template <std::ForwardIterator begin_iterator_type,
typename end_iterator_type>
367 void assign(begin_iterator_type begin_it, end_iterator_type end_it)
369 requires is_compatible_this<begin_iterator_type> &&
389 template <std::ranges::ForwardRange rng_type = value_type>
392 requires is_compatible_value<rng_type>
484 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
493 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
522 | ranges::view::const_;
565 return (*
this)[
size()-1];
572 return (*
this)[
size()-1];
607 return {data_values, data_delimiters};
649 return data_delimiters.size() - 1;
668 return data_delimiters.max_size() - 1;
688 return data_delimiters.capacity();
715 data_delimiters.reserve(new_cap + 1);
739 data_values.shrink_to_fit();
740 data_delimiters.shrink_to_fit();
760 return data_values.size();
776 return data_values.capacity();
799 data_values.reserve(new_cap);
821 data_delimiters.clear();
822 data_delimiters.push_back(0);
849 template <std::ranges::ForwardRange rng_type>
851 requires is_compatible_value<rng_type>
853 return insert(pos, 1, std::forward<rng_type>(value));
881 template <std::ranges::ForwardRange rng_type>
883 requires is_compatible_value<rng_type>
889 return begin() + pos_as_num;
906 data_values.reserve(data_values.size() + count * value_len);
910 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
915 size_t i = data_delimiters[pos_as_num];
916 for (
size_t j = 0; j < count; ++j)
917 for (
auto && v : value)
918 data_values[i++] = v;
920 data_delimiters.reserve(data_values.size() + count);
921 data_delimiters.insert(data_delimiters.begin() + pos_as_num,
923 *(data_delimiters.begin() + pos_as_num));
927 data_delimiters[pos_as_num + i + 1] += value_len * (i + 1);
931 std::for_each(data_delimiters.begin() + pos_as_num + count + 1,
932 data_delimiters.end(),
933 [full_len = value_len * count] (
auto & d) { d += full_len; });
935 return begin() + pos_as_num;
961 template <std::ForwardIterator begin_iterator_type,
typename end_iterator_type>
964 requires is_compatible_this<begin_iterator_type> &&
970 if (last - first == 0)
971 return begin() + pos_as_num;
977 data_delimiters.reserve(data_values.size() + ilist.size());
978 data_delimiters.insert(data_delimiters.begin() + pos_as_num,
980 *(data_delimiters.begin() + pos_as_num));
985 for (
size_type i = 0; i < ilist.size(); ++i, ++first)
993 data_delimiters[pos_as_num + 1 + i] += full_len;
1000 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
1005 size_t i = data_delimiters[pos_as_num];
1006 for (
auto && v0 : ilist)
1007 for (
auto && v1 : v0)
1008 data_values[i++] = v1;
1013 std::for_each(data_delimiters.begin() + pos_as_num + ilist.size() + 1,
1014 data_delimiters.end(),
1015 [full_len] (
auto & d) { d += full_len; });
1017 return begin() + pos_as_num;
1039 template <std::ranges::ForwardRange rng_type>
1041 requires is_compatible_value<rng_type>
1043 return insert(pos, ilist.begin(), ilist.end());
1068 if (last - first == 0)
1069 return begin() + dist;
1075 for (; first != last; ++first)
1078 data_values.erase(data_values.begin() + data_delimiters[distf],
1079 data_values.begin() + data_delimiters[dist]);
1081 data_delimiters.erase(data_delimiters.begin() + distf + 1,
1082 data_delimiters.begin() + dist + 1);
1087 data_delimiters.end(),
1088 [sum_size] (
auto & d) { d -= sum_size; });
1089 return begin() + dist;
1112 return erase(pos, pos + 1);
1131 template <std::ranges::ForwardRange rng_type>
1133 requires is_compatible_value<rng_type>
1136 data_delimiters.push_back(data_delimiters.back() +
seqan3::size(value));
1158 auto back_length = data_delimiters[
size()] - data_delimiters[
size() - 1];
1159 data_values.resize(data_values.size() - back_length);
1160 data_delimiters.pop_back();
1192 data_delimiters.resize(count + 1, data_delimiters.back());
1193 data_values.resize(data_delimiters.back());
1201 template <std::ranges::ForwardRange rng_type>
1203 requires is_compatible_value<rng_type>
1210 else if (count >
size())
1227 std::swap(data_values, rhs.data_values);
1228 std::swap(data_delimiters, rhs.data_delimiters);
1234 std::swap(data_values, rhs.data_values);
1235 std::swap(data_delimiters, rhs.data_delimiters);
1246 return data() == rhs.data();
1252 return data() != rhs.data();
1258 return data() < rhs.data();
1264 return data() > rhs.data();
1270 return data() <= rhs.data();
1276 return data() >= rhs.data();
1287 template <CerealArchive archive_t>
1288 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1290 archive(data_values, data_delimiters);
concatenated_sequences()=default
Default constructors.
constexpr concatenated_sequences & operator=(concatenated_sequences const &)=default
Default constructors.
detail::random_access_iterator< concatenated_sequences > iterator
The iterator type of this container (a random access iterator).
Definition: concatenated_sequences.hpp:117
typename value_type< t >::type value_type_t
Shortcut for seqan3::value_type (TransformationTrait shortcut).
Definition: pre.hpp:48
::ranges::subrange< it_t, sen_t, k > subrange
Create a view from a pair of iterator and sentinel.
Definition: ranges:339
void concat_reserve(size_type const new_cap)
Increase the concat_capacity() to a value that's greater or equal to new_cap.
Definition: concatenated_sequences.hpp:797
const_reference at(size_type const i) const
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:489
size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition: concatenated_sequences.hpp:666
iterator erase(const_iterator pos)
Removes specified elements from the container.
Definition: concatenated_sequences.hpp:1110
iterator end() noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:446
void reserve(size_type const new_cap)
Increase the capacity to a value that's greater or equal to new_cap.
Definition: concatenated_sequences.hpp:713
Provides C++20 additions to the <iterator> header.
constexpr void swap(concatenated_sequences &rhs) noexcept
Swap contents with another instance.
Definition: concatenated_sequences.hpp:1225
Provides various shortcuts for common std::ranges functions.
iterator erase(const_iterator first, const_iterator last)
Removes specified elements from the container.
Definition: concatenated_sequences.hpp:1064
concatenated_sequences(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition: concatenated_sequences.hpp:256
constexpr bool operator>=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is greater than or equal to rhs.
Definition: concatenated_sequences.hpp:1274
Two types are "compatible" if their seqan3::dimension_v and their seqan3::innermost_value_type_t are ...
static constexpr bool is_compatible_value
Whether a type satisfies seqan3::Compatible with this class's value_type or reference type...
Definition: concatenated_sequences.hpp:164
void pop_back()
Removes the last element of the container.
Definition: concatenated_sequences.hpp:1155
Provides the seqan3::detail::random_access_iterator class.
void assign(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition: concatenated_sequences.hpp:320
const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:458
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
The main SeqAn3 namespace.
std::pair< decltype(data_values) const &, decltype(data_delimiters) const & > data() const
Provides direct, unsafe access to underlying data structures.
Definition: concatenated_sequences.hpp:611
decltype(data_values|ranges::view::slice(0, 1)) reference
A proxy of type ranges::view::slice that represents the range on the concatenated vector...
Definition: concatenated_sequences.hpp:109
constexpr bool operator>(concatenated_sequences const &rhs) const noexcept
Checks whether *this is greater than rhs.
Definition: concatenated_sequences.hpp:1262
typename difference_type< t >::type difference_type_t
Shortcut for seqan3::difference_type (TransformationTrait shortcut).
Definition: pre.hpp:166
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition: slice.hpp:144
size_type concat_size() const noexcept
Returns the cumulative size of all elements in the container.
Definition: concatenated_sequences.hpp:758
constexpr void swap(concatenated_sequences &&rhs) noexcept
Swap contents with another instance.
Definition: concatenated_sequences.hpp:1232
const_reference concat() const
Return the concatenation of all members.
Definition: concatenated_sequences.hpp:595
difference_type_t< data_delimiters_type > difference_type
A signed integer type (usually std::ptrdiff_t)
Definition: concatenated_sequences.hpp:125
void clear() noexcept
Removes all elements from the container.
Definition: concatenated_sequences.hpp:818
size_type_t< data_delimiters_type > size_type
An unsigned integer type (usually std::size_t)
Definition: concatenated_sequences.hpp:129
Container that stores sequences concatenated internally.
Definition: concatenated_sequences.hpp:89
constexpr auto common
A range adaptor that makes any range model std::ranges::CommonRange (at the expense of some performan...
Definition: ranges:447
bool empty() const noexcept
Checks whether the container is empty.
Definition: concatenated_sequences.hpp:631
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
size_type concat_capacity() const noexcept
Returns the concatenated size the container has currently allocated space for.
Definition: concatenated_sequences.hpp:774
concatenated_sequences(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:277
Provides various type traits.
const_reference operator[](size_type const i) const
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:518
size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: concatenated_sequences.hpp:647
std::pair< decltype(data_values) &, decltype(data_delimiters) & > data()
Provides direct, unsafe access to underlying data structures.
Definition: concatenated_sequences.hpp:605
iterator insert(const_iterator pos, rng_type &&value) requires is_compatible_value< rng_type >
Inserts value before position in the container.
Definition: concatenated_sequences.hpp:850
reference front()
Return the first element as a view. Calling front on an empty container is undefined.
Definition: concatenated_sequences.hpp:537
void resize(size_type const count)
Resizes the container to contain count elements.
Definition: concatenated_sequences.hpp:1189
decltype(std::as_const(data_values)|ranges::view::slice(0, 1)|ranges::view::const_) const_reference
An immutable proxy of type ranges::view::slice that represents the range on the concatenated vector...
Definition: concatenated_sequences.hpp:113
constexpr bool operator!=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition: concatenated_sequences.hpp:1250
~concatenated_sequences()=default
Default constructors.
The SizedSentinel concept specifies that an object of the iterator type I and an object of the sentin...
Adaptations of concepts from the Ranges TS.
iterator begin() noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:416
const_reference front() const
Return the first element as a view. Calling front on an empty container is undefined.
Definition: concatenated_sequences.hpp:544
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:422
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
Adaptions of concepts from the Cereal library.
static constexpr bool is_compatible_this
Whether a type satisfies seqan3::Compatible with this class.
Definition: concatenated_sequences.hpp:155
void assign(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition: concatenated_sequences.hpp:367
void resize(size_type const count, rng_type &&value) requires is_compatible_value< rng_type >
Resizes the container to contain count elements.
Definition: concatenated_sequences.hpp:1202
typename size_type< t >::type size_type_t
Shortcut for seqan3::size_type (TransformationTrait shortcut).
Definition: pre.hpp:195
iterator insert(const_iterator pos, std::initializer_list< rng_type > const &ilist) requires is_compatible_value< rng_type >
Inserts elements from initializer list before position in the container.
Definition: concatenated_sequences.hpp:1040
size_type capacity() const noexcept
Returns the number of elements that the container has currently allocated space for.
Definition: concatenated_sequences.hpp:686
reference operator[](size_type const i)
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:511
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:452
concatenated_sequences(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition: concatenated_sequences.hpp:199
constexpr bool operator<=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is less than or equal to rhs.
Definition: concatenated_sequences.hpp:1268
void shrink_to_fit()
Requests the removal of unused capacity.
Definition: concatenated_sequences.hpp:737
constexpr bool operator<(concatenated_sequences const &rhs) const noexcept
Checks whether *this is less than rhs.
Definition: concatenated_sequences.hpp:1256
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:97
iterator insert(const_iterator pos, size_type const count, rng_type &&value) requires is_compatible_value< rng_type >
Inserts count copies of value before position in the container.
Definition: concatenated_sequences.hpp:882
reference concat()
Return the concatenation of all members.
Definition: concatenated_sequences.hpp:589
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:428
detail::random_access_iterator< concatenated_sequences const > const_iterator
The const iterator type of this container (a random access iterator).
Definition: concatenated_sequences.hpp:121
Specifies requirements of a Range type for which begin returns a type that models std::ForwardIterato...
reference back()
Return the last element as a view.
Definition: concatenated_sequences.hpp:562
void assign(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:390
Adaptations of concepts from the standard library.
iterator insert(const_iterator pos, begin_iterator_type first, end_iterator_type last)
Inserts elements from range [first, last) before position in the container.
Definition: concatenated_sequences.hpp:962
const_reference back() const
Return the last element as a view.
Definition: concatenated_sequences.hpp:569
reference at(size_type const i)
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:480
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:179
constexpr bool operator==(concatenated_sequences const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition: concatenated_sequences.hpp:1244
void assign(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition: concatenated_sequences.hpp:343
concatenated_sequences(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition: concatenated_sequences.hpp:228
void push_back(rng_type &&value) requires is_compatible_value< rng_type >
Appends the given element value to the end of the container.
Definition: concatenated_sequences.hpp:1132
concatenated_sequences & operator=(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:298