42 #include <range/v3/view/take_while.hpp> 43 #include <range/v3/algorithm/copy.hpp> 81 template <std::ranges::View urng_t,
typename fun_t,
bool or_throw>
82 class view_take_until :
public ranges::view_interface<view_take_until<urng_t, fun_t, or_throw>>
87 "The functor type for view::take_until must model std::Invocable<fun_t, reference_t<urng_t>>.");
88 static_assert(
std::Boolean<std::result_of_t<fun_t&&(reference_t<urng_t>)>>,
89 "The functor type for view::take_until must return std::Boolean.");
95 ranges::semiregular_t<fun_t> fun;
98 static constexpr
bool const_iterable = const_iterable_concept<urng_t> &&
106 template <
typename rng_t>
107 class iterator_type :
public inherited_iterator_base<iterator_type<rng_t>, std::ranges::iterator_t<rng_t>>
113 using base_t = inherited_iterator_base<iterator_type, std::ranges::iterator_t<rng_t>>;
116 using fun_ref_t = std::conditional_t<std::is_const_v<rng_t>,
117 std::remove_reference_t<fun_t>
const &,
118 std::remove_reference_t<fun_t> &>;
120 ranges::semiregular_t<fun_ref_t> fun;
126 iterator_type() =
default;
127 constexpr iterator_type(iterator_type
const & rhs) =
default;
128 constexpr iterator_type(iterator_type && rhs) =
default;
129 constexpr iterator_type &
operator=(iterator_type
const & rhs) =
default;
130 constexpr iterator_type &
operator=(iterator_type && rhs) =
default;
131 ~iterator_type() =
default;
134 iterator_type(base_base_t
const & it) :
139 iterator_type(base_base_t it, fun_ref_t _fun) :
140 base_t{it}, fun{_fun} {}
147 using difference_type =
typename std::iterator_traits<base_base_t>::difference_type;
148 using value_type =
typename std::iterator_traits<base_base_t>::value_type;
149 using reference =
typename std::iterator_traits<base_base_t>::reference;
150 using pointer =
typename std::iterator_traits<base_base_t>::pointer;
151 using iterator_category =
typename std::iterator_traits<base_base_t>::iterator_category;
158 bool operator==(iterator_type
const & rhs)
const noexcept(!or_throw)
160 return static_cast<base_base_t
>(*this) ==
static_cast<base_base_t
>(rhs);
163 bool operator==(sentinel_type
const & rhs)
const noexcept(!or_throw)
165 if (static_cast<base_base_t>(*
this) == rhs)
167 if constexpr (or_throw)
168 throw unexpected_end_of_input{
"Reached end of input before functor evaluated to true."};
176 friend bool operator==(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(!or_throw)
181 bool operator!=(sentinel_type
const & rhs)
const noexcept(!or_throw)
183 return !(*
this == rhs);
186 bool operator!=(iterator_type
const & rhs)
const noexcept(!or_throw)
188 return static_cast<base_base_t
>(*this) !=
static_cast<base_base_t
>(rhs);
191 friend bool operator!=(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(!or_throw)
202 using reference = reference_t<urng_t>;
205 using const_reference = detail::transformation_trait_or_t<seqan3::reference<urng_t const>,
void>;
207 using value_type = value_type_t<urng_t>;
209 using size_type = void;
211 using difference_type = difference_type_t<urng_t>;
213 using iterator = iterator_type<urng_t>;
215 using const_iterator = detail::transformation_trait_or_t<std::type_identity<iterator_type<urng_t const>>,
void>;
221 view_take_until() =
default;
222 constexpr view_take_until(view_take_until
const & rhs) =
default;
223 constexpr view_take_until(view_take_until && rhs) =
default;
224 constexpr view_take_until &
operator=(view_take_until
const & rhs) =
default;
225 constexpr view_take_until &
operator=(view_take_until && rhs) =
default;
226 ~view_take_until() =
default;
232 view_take_until(urng_t _urange, fun_t _fun)
233 : urange{std::move(_urange)}, fun{std::forward<fun_t>(_fun)}
253 iterator
begin() noexcept
255 return {seqan3::begin(urange),
static_cast<fun_t &
>(fun)};
259 const_iterator
begin() const noexcept
260 requires const_iterable
266 const_iterator
cbegin() const noexcept
267 requires const_iterable
285 sentinel_type
end() noexcept
287 return {seqan3::end(urange)};
291 sentinel_type
end() const noexcept
292 requires const_iterable
298 sentinel_type
cend() const noexcept
299 requires const_iterable
310 template <sequence_container_concept container_t>
311 operator container_t()
313 requires
std::CommonReference<
reference_t<container_t>, reference>
322 template <sequence_container_concept container_t>
323 operator container_t() const
325 requires
std::CommonReference<
reference_t<container_t>, reference> && const_iterable_concept<urng_t>
336 template <
typename urng_t,
typename fun_t,
bool or_throw = false>
337 view_take_until(urng_t, fun_t) -> view_take_until<std::remove_reference_t<urng_t>, fun_t, or_throw>;
346 template <
bool or_throw>
347 class take_until_fn :
public pipable_adaptor_base<take_until_fn<or_throw>>
351 using base_t = pipable_adaptor_base<take_until_fn<or_throw>>;
355 using base_t::base_t;
368 template <std::ranges::View urng_t,
typename fun_t>
369 static auto impl(urng_t urange, fun_t && fun)
371 return view_take_until<urng_t, fun_t, or_throw>{std::move(urange), std::forward<fun_t>(fun)};
382 template <std::ranges::ViewableRange urng_t,
typename fun_t>
383 static auto impl(urng_t && urange, fun_t && fun)
385 return impl(
view::all(std::forward<urng_t>(urange)), std::forward<fun_t>(fun));
448 inline auto constexpr
take_until = detail::take_until_fn<false>{};
::ranges::cbegin cbegin
Alias for ranges::cbegin. Returns an iterator to the beginning of a range.
Definition: ranges:245
auto constexpr take_until
A view adaptor that returns elements from the underlying range until the functor evaluates to true (o...
Definition: take_until.hpp:448
Provides exceptions used in the I/O module.
Provides C++20 additions to the <iterator> header.
Contains various shortcuts for common std::ranges functions.
Provides the seqan3::detail::inherited_iterator_base template.
Specifies whether the given callable is invocable with the given arguments.
SeqAn specific customisations in the standard namespace.
Definition: align_result.hpp:221
::ranges::copy copy
Alias for ranges::copy. Copies a range of elements to a new location.
Definition: ranges:200
t & operator=(t1 const &rhs)
Assignment operator.
Additional non-standard concepts for ranges.
Auxiliary header for the view submodule .
::ranges::iterator_t iterator_t
Alias for ranges::iterator_t. Obtains the iterator type of a range.
Definition: ranges:225
Adaptations of concepts from the Ranges TS.
::ranges::sentinel_t sentinel_t
Alias for ranges::sentinel_t. Obtains the sentinel type of a range.
Definition: ranges:220
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:185
Provides seqan3::view::all.
The SeqAn3 namespace for views.
Specifies whether the given callable is invocable with the given arguments and equality preserving (i...
Definition: aligned_sequence_concept.hpp:288
auto constexpr take_until_or_throw
A view adaptor that returns elements from the underlying range until the functor evaluates to true (t...
Definition: take_until.hpp:462
Provides C++20 additions to the type_traits header.
Specifies that a type can be used in Boolean contexts.
constexpr auto all
A view that safely wraps a container (you will likely not need to use this unless defining a new view...
Definition: view_all.hpp:95
Provides various metafunctions used by the range module.
Provides various metafunctions for use on iterators.
::ranges::cend cend
Alias for ranges::cend. Returns an iterator to the end of a range.
Definition: ranges:250
Adaptations of concepts from the standard library.
constexpr auto back_inserter(container_t &container)
Create a std::back_insert_iterator for the argument.
Definition: iterator:79
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:190