23# include <cereal/types/vector.hpp>
79template <
typename underlying_container_type,
83 && std::is_same_v<std::ranges::range_size_t<underlying_container_type>,
84 std::ranges::range_value_t<data_delimiters_type>>
92 data_delimiters_type data_delimiters{0};
120 decltype(std::declval<std::decay_t<underlying_container_type>
const &>() |
views::slice(0, 1));
127 using iterator = detail::random_access_iterator<concatenated_sequences>;
134 using const_iterator = detail::random_access_iterator<concatenated_sequences const>;
148 using size_type = std::ranges::range_size_t<data_delimiters_type>;
159 template <std::ranges::range t>
162 return range_dimension_v<t> == range_dimension_v<value_type>
163 && std::convertible_to<std::ranges::range_reference_t<t>, std::ranges::range_value_t<value_type>>;
166 static constexpr bool is_compatible_with_value_type_aux(...)
178 template <std::ranges::range t>
187 template <
typename t>
188 requires is_compatible_with_value_type<std::iter_reference_t<t>>
197 template <std::ranges::range t>
198 requires is_compatible_with_value_type<std::ranges::range_reference_t<t>>
234 template <std::ranges::input_range rng_of_rng_type>
236 requires range_value_t_is_compatible_with_value_type<rng_of_rng_type>
238 if constexpr (std::ranges::sized_range<rng_of_rng_type>)
239 data_delimiters.reserve(std::ranges::size(rng_of_rng) + 1);
241 for (
auto && val : rng_of_rng)
243 data_values.insert(data_values.end(), val.begin(), val.end());
244 data_delimiters.push_back(data_delimiters.back() + val.size());
263 template <std::ranges::forward_range rng_type>
265 requires is_compatible_with_value_type<rng_type>
271 insert(
cend(), count, std::forward<rng_type>(value));
291 template <std::forward_iterator begin_iterator_type,
typename end_iterator_type>
293 requires std::sized_sentinel_for<end_iterator_type, begin_iterator_type>
294 && iter_value_t_is_compatible_with_value_type<begin_iterator_type>
313 template <std::ranges::forward_range value_type_t = value_type>
314 requires is_compatible_with_value_type<value_type_t>
334 template <std::ranges::forward_range value_type_t>
336 requires is_compatible_with_value_type<value_type_t>
357 template <std::ranges::input_range rng_of_rng_type>
358 void assign(rng_of_rng_type && rng_of_rng)
359 requires range_value_t_is_compatible_with_value_type<rng_of_rng_type>
380 template <std::ranges::forward_range rng_type>
382 requires (is_compatible_with_value_type<rng_type>)
405 template <std::forward_iterator begin_iterator_type,
typename end_iterator_type>
406 void assign(begin_iterator_type begin_it, end_iterator_type end_it)
407 requires iter_value_t_is_compatible_with_value_type<begin_iterator_type>
408 && std::sized_sentinel_for<end_iterator_type, begin_iterator_type>
428 template <std::ranges::forward_range rng_type = value_type>
430 requires is_compatible_with_value_type<rng_type>
527 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
536 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
559 return data_values |
views::slice(data_delimiters[i], data_delimiters[i + 1]);
566 return data_values |
views::slice(data_delimiters[i], data_delimiters[i + 1]);
613 return (*
this)[
size() - 1];
620 return (*
this)[
size() - 1];
659 return {data_values, data_delimiters};
665 return {data_values, data_delimiters};
706 return data_delimiters.size() - 1;
727 return data_delimiters.max_size() - 1;
749 return data_delimiters.capacity();
776 data_delimiters.reserve(new_cap + 1);
800 data_values.shrink_to_fit();
801 data_delimiters.shrink_to_fit();
823 return data_values.size();
841 return data_values.capacity();
866 data_values.reserve(new_cap);
888 data_delimiters.clear();
889 data_delimiters.push_back(0);
918 template <std::ranges::forward_range rng_type>
920 requires is_compatible_with_value_type<rng_type>
922 return insert(pos, 1, std::forward<rng_type>(value));
952 template <std::ranges::forward_range rng_type>
954 requires is_compatible_with_value_type<rng_type>
959 return begin() + pos_as_num;
971 if constexpr (std::ranges::sized_range<rng_type>)
972 value_len = std::ranges::size(value);
976 data_values.reserve(data_values.size() + count * value_len);
978 views::repeat_n(std::ranges::range_value_t<rng_type>{}, count * value_len) | std::views::common;
980 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
982 std::ranges::end(placeholder));
985 size_t i = data_delimiters[pos_as_num];
986 for (
size_t j = 0; j < count; ++j)
987 for (
auto && v : value)
988 data_values[i++] = v;
990 data_delimiters.reserve(data_values.size() + count);
991 data_delimiters.insert(data_delimiters.begin() + pos_as_num, count, *(data_delimiters.begin() + pos_as_num));
995 data_delimiters[pos_as_num + i + 1] += value_len * (i + 1);
999 std::for_each(data_delimiters.begin() + pos_as_num + count + 1,
1000 data_delimiters.end(),
1001 [full_len = value_len * count](
auto & d)
1006 return begin() + pos_as_num;
1035 template <std::forward_iterator begin_iterator_type,
typename end_iterator_type>
1037 requires iter_value_t_is_compatible_with_value_type<begin_iterator_type>
1038 && std::sized_sentinel_for<end_iterator_type, begin_iterator_type>
1042 if (last - first == 0)
1043 return begin() + pos_as_num;
1046 std::ranges::subrange<begin_iterator_type, end_iterator_type>(first,
1048 std::ranges::distance(first, last));
1050 data_delimiters.reserve(data_values.size() + ilist.size());
1051 data_delimiters.insert(data_delimiters.begin() + pos_as_num,
1053 *(data_delimiters.begin() + pos_as_num));
1057 for (
size_type i = 0; i < ilist.size(); ++i, ++first)
1059 full_len += std::ranges::distance(*first);
1060 data_delimiters[pos_as_num + 1 + i] += full_len;
1064 auto placeholder =
views::repeat_n(std::ranges::range_value_t<value_type>{}, full_len) | std::views::common;
1066 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
1068 std::ranges::end(placeholder));
1071 size_t i = data_delimiters[pos_as_num];
1072 for (
auto && v0 : ilist)
1073 for (
auto && v1 : v0)
1074 data_values[i++] = v1;
1078 std::for_each(data_delimiters.begin() + pos_as_num + ilist.size() + 1,
1079 data_delimiters.end(),
1080 [full_len](
auto & d)
1085 return begin() + pos_as_num;
1109 template <std::ranges::forward_range rng_type>
1111 requires is_compatible_with_value_type<rng_type>
1113 return insert(pos, ilist.begin(), ilist.end());
1140 if (last - first == 0)
1141 return begin() + dist;
1147 for (; first != last; ++first)
1148 sum_size += std::ranges::size(*first);
1150 data_values.erase(data_values.begin() + data_delimiters[distf], data_values.begin() + data_delimiters[dist]);
1152 data_delimiters.erase(data_delimiters.begin() + distf + 1, data_delimiters.begin() + dist + 1);
1157 data_delimiters.end(),
1158 [sum_size](
auto & d)
1162 return begin() + dist;
1187 return erase(pos, pos + 1);
1211 template <std::ranges::forward_range rng_type>
1213 requires is_compatible_with_value_type<rng_type>
1215 data_values.insert(data_values.end(),
std::ranges::begin(value), std::ranges::end(value));
1216 data_delimiters.push_back(data_delimiters.back() + std::ranges::size(value));
1239 data_delimiters.push_back(data_delimiters.back());
1262 void last_push_back(std::ranges::range_value_t<underlying_container_type>
const value)
1264 data_values.push_back(value);
1265 ++data_delimiters.back();
1289 template <std::ranges::forward_range rng_type>
1291 requires is_compatible_with_value_type<rng_type>
1293 data_values.insert(data_values.end(),
std::ranges::begin(value), std::ranges::end(value));
1294 data_delimiters.back() += std::ranges::size(value);
1318 auto back_length = data_delimiters[
size()] - data_delimiters[
size() - 1];
1319 data_values.resize(data_values.size() - back_length);
1320 data_delimiters.pop_back();
1354 data_delimiters.resize(count + 1, data_delimiters.back());
1355 data_values.resize(data_delimiters.back());
1363 template <std::ranges::forward_range rng_type>
1365 requires is_compatible_with_value_type<rng_type>
1368 assert(
concat_size() + count * std::ranges::size(value) < data_values.max_size());
1372 else if (count >
size())
1391 std::swap(data_values, rhs.data_values);
1392 std::swap(data_delimiters, rhs.data_delimiters);
1398 std::swap(data_values, rhs.data_values);
1399 std::swap(data_delimiters, rhs.data_delimiters);
1413 return raw_data() == rhs.raw_data();
1422 return raw_data() != rhs.raw_data();
1431 return raw_data() < rhs.raw_data();
1440 return raw_data() > rhs.raw_data();
1449 return raw_data() <= rhs.raw_data();
1458 return raw_data() >= rhs.raw_data();
1469 template <cereal_archive archive_t>
1470 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1472 archive(data_values, data_delimiters);
Adaptions of concepts from the Cereal library.
Container that stores sequences concatenated internally.
Definition concatenated_sequences.hpp:86
detail::random_access_iterator< concatenated_sequences const > const_iterator
The const iterator type of this container (a random access iterator).
Definition concatenated_sequences.hpp:134
constexpr concatenated_sequences & operator=(concatenated_sequences const &)=default
Default constructors.
concatenated_sequences(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition concatenated_sequences.hpp:235
size_type capacity() const noexcept
Returns the number of elements that the container has currently allocated space for.
Definition concatenated_sequences.hpp:747
concatenated_sequences()=default
Default constructors.
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:774
void last_push_back(std::ranges::range_value_t< underlying_container_type > const value)
Appends the given element-of-element value to the end of the underlying container.
Definition concatenated_sequences.hpp:1262
void last_append(rng_type &&value)
Appends the given elements to the end of the underlying container (increases size of last element by ...
Definition concatenated_sequences.hpp:1290
const_reference front() const
Return the first element as a view. Calling front on an empty container is undefined.
Definition concatenated_sequences.hpp:590
constexpr concatenated_sequences(concatenated_sequences &&)=default
Default constructors.
const_reference back() const
Return the last element as a view.
Definition concatenated_sequences.hpp:617
reference at(size_type const i)
Return the i-th element as a view.
Definition concatenated_sequences.hpp:523
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition concatenated_sequences.hpp:467
reference concat()
Return the concatenation of all members.
Definition concatenated_sequences.hpp:639
constexpr bool operator>(concatenated_sequences const &rhs) const noexcept
Checks whether *this is greater than rhs.
Definition concatenated_sequences.hpp:1438
bool empty() const noexcept
Checks whether the container is empty.
Definition concatenated_sequences.hpp:686
reference operator[](size_type const i)
Return the i-th element as a view.
Definition concatenated_sequences.hpp:556
concatenated_sequences & operator=(std::initializer_list< value_type_t > ilist)
Construct/assign from std::initializer_list.
Definition concatenated_sequences.hpp:335
constexpr void swap(concatenated_sequences &rhs) noexcept
Swap contents with another instance.
Definition concatenated_sequences.hpp:1389
iterator end() noexcept
Returns an iterator to the element following the last element of the container.
Definition concatenated_sequences.hpp:487
void clear() noexcept
Removes all elements from the container.
Definition concatenated_sequences.hpp:885
iterator begin() noexcept
Returns an iterator to the first element of the container.
Definition concatenated_sequences.hpp:455
~concatenated_sequences()=default
Default constructors.
void pop_back()
Removes the last element of the container.
Definition concatenated_sequences.hpp:1315
reference front()
Return the first element as a view. Calling front on an empty container is undefined.
Definition concatenated_sequences.hpp:583
reference back()
Return the last element as a view.
Definition concatenated_sequences.hpp:610
size_type concat_capacity() const noexcept
Returns the concatenated size the container has currently allocated space for.
Definition concatenated_sequences.hpp:839
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition concatenated_sequences.hpp:461
decltype(std::declval< std::decay_t< underlying_container_type > const & >()|views::slice(0, 1)) const_reference
An immutable views::slice that represents "one element", typically a std::span or std::string_view.
Definition concatenated_sequences.hpp:120
std::pair< decltype(data_values) &, decltype(data_delimiters) & > raw_data()
Provides direct, unsafe access to underlying data structures.
Definition concatenated_sequences.hpp:657
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the container.
Definition concatenated_sequences.hpp:493
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:1036
iterator insert(const_iterator pos, size_type const count, rng_type &&value)
Inserts count copies of value before position in the container.
Definition concatenated_sequences.hpp:953
void shrink_to_fit()
Requests the removal of unused capacity.
Definition concatenated_sequences.hpp:798
constexpr concatenated_sequences(concatenated_sequences const &)=default
Default constructors.
iterator insert(const_iterator pos, rng_type &&value)
Inserts value before position in the container.
Definition concatenated_sequences.hpp:919
concatenated_sequences(std::initializer_list< value_type_t > ilist)
Construct/assign from std::initializer_list.
Definition concatenated_sequences.hpp:315
constexpr bool operator==(concatenated_sequences const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition concatenated_sequences.hpp:1411
const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the container.
Definition concatenated_sequences.hpp:499
void resize(size_type const count, rng_type &&value)
Resizes the container to contain count elements.
Definition concatenated_sequences.hpp:1364
void assign(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition concatenated_sequences.hpp:381
detail::random_access_iterator< concatenated_sequences > iterator
The iterator type of this container (a random access iterator).
Definition concatenated_sequences.hpp:127
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:725
static constexpr bool is_compatible_with_value_type
Whether a type is compatible with this class's value_type or reference type.
Definition concatenated_sequences.hpp:179
void assign(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition concatenated_sequences.hpp:429
size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition concatenated_sequences.hpp:704
void push_back(rng_type &&value)
Appends the given element value to the end of the container.
Definition concatenated_sequences.hpp:1212
constexpr bool operator!=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition concatenated_sequences.hpp:1420
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:864
void assign(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition concatenated_sequences.hpp:358
static constexpr bool range_value_t_is_compatible_with_value_type
Whether a type is compatible with this class.
Definition concatenated_sequences.hpp:199
void push_back()
Appends an empty element to the end of the container.
Definition concatenated_sequences.hpp:1237
static constexpr bool iter_value_t_is_compatible_with_value_type
Whether a type is compatible with this class.
Definition concatenated_sequences.hpp:189
iterator erase(const_iterator pos)
Removes specified elements from the container.
Definition concatenated_sequences.hpp:1185
void resize(size_type const count)
Resizes the container to contain count elements.
Definition concatenated_sequences.hpp:1351
const_reference concat() const
Return the concatenation of all members.
Definition concatenated_sequences.hpp:645
value_type reference
A views::slice that represents "one element", typically a std::span.
Definition concatenated_sequences.hpp:112
constexpr bool operator>=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is greater than or equal to rhs.
Definition concatenated_sequences.hpp:1456
const_reference operator[](size_type const i) const
Return the i-th element as a view.
Definition concatenated_sequences.hpp:563
size_type concat_size() const noexcept
Returns the cumulative size of all elements in the container.
Definition concatenated_sequences.hpp:821
constexpr void swap(concatenated_sequences &&rhs) noexcept
Swap contents with another instance.
Definition concatenated_sequences.hpp:1396
concatenated_sequences(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition concatenated_sequences.hpp:264
void assign(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition concatenated_sequences.hpp:406
std::pair< decltype(data_values) const &, decltype(data_delimiters) const & > raw_data() const
Provides direct, unsafe access to underlying data structures.
Definition concatenated_sequences.hpp:663
decltype(std::declval< std::decay_t< underlying_container_type > & >()|views::slice(0, 1)) value_type
A views::slice that represents "one element", typically a std::span.
Definition concatenated_sequences.hpp:105
constexpr bool operator<(concatenated_sequences const &rhs) const noexcept
Checks whether *this is less than rhs.
Definition concatenated_sequences.hpp:1429
std::ranges::range_size_t< data_delimiters_type > size_type
An unsigned integer type (usually std::size_t)
Definition concatenated_sequences.hpp:148
concatenated_sequences(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition concatenated_sequences.hpp:292
iterator insert(const_iterator pos, std::initializer_list< rng_type > const &ilist)
Inserts elements from initializer list before position in the container.
Definition concatenated_sequences.hpp:1110
constexpr concatenated_sequences & operator=(concatenated_sequences &&)=default
Default constructors.
const_reference at(size_type const i) const
Return the i-th element as a view.
Definition concatenated_sequences.hpp:532
iterator erase(const_iterator first, const_iterator last)
Removes specified elements from the container.
Definition concatenated_sequences.hpp:1136
std::ranges::range_difference_t< data_delimiters_type > difference_type
A signed integer type (usually std::ptrdiff_t)
Definition concatenated_sequences.hpp:141
constexpr bool operator<=(concatenated_sequences const &rhs) const noexcept
Checks whether *this is less than or equal to rhs.
Definition concatenated_sequences.hpp:1447
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:175
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
A more refined container concept than seqan3::random_access_container.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::views::repeat_n.
Provides seqan3::views::slice.
Adaptations of concepts from the standard library.