SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
all_view.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <ranges>
16
17#if __cpp_lib_ranges >= 202110L
18
20
21namespace seqan3::detail
22{
23using std::ranges::owning_view;
26
27} // namespace seqan3::detail
28#else
31
32namespace seqan3::detail
33{
34
39template <std::ranges::range rng_t>
40 requires std::movable<rng_t> && (!seqan3::detail::is_type_specialisation_of_v<rng_t, std::initializer_list>)
41class owning_view : public std::ranges::view_interface<owning_view<rng_t>>
42{
43private:
45 rng_t rng = rng_t();
46
47public:
49 requires std::default_initializable<rng_t>
50 = default;
51 owning_view(owning_view const &) = delete;
52 owning_view & operator=(owning_view const &) = delete;
53 owning_view(owning_view &&) = default;
54 owning_view & operator=(owning_view &&) = default;
55 ~owning_view() = default;
56
58 constexpr owning_view(rng_t && r) : rng(std::move(r))
59 {}
60
62 constexpr rng_t & base() & noexcept
63 {
64 return rng;
65 }
66
68 constexpr rng_t const & base() const & noexcept
69 {
70 return rng;
71 }
72
74 constexpr rng_t && base() && noexcept
75 {
76 return std::move(rng);
77 }
78
80 constexpr rng_t const && base() const && noexcept
81 {
82 return std::move(rng);
83 }
84
86 constexpr std::ranges::iterator_t<rng_t> begin()
87 {
88 return std::ranges::begin(rng);
89 }
90
92 constexpr auto begin() const
93 requires std::ranges::range<rng_t const>
94 {
95 return std::ranges::begin(rng);
96 }
97
99 constexpr std::ranges::sentinel_t<rng_t> end()
100 {
101 return std::ranges::end(rng);
102 }
103
105 constexpr auto end() const
106 requires std::ranges::range<rng_t const>
107 {
108 return std::ranges::end(rng);
109 }
110
112 constexpr bool empty()
113 requires requires { std::ranges::empty(rng); }
114 {
115 return std::ranges::empty(rng);
116 }
117
119 constexpr bool empty() const
120 requires requires { std::ranges::empty(rng); }
121 {
122 return std::ranges::empty(rng);
123 }
124
126 constexpr auto size()
127 requires std::ranges::sized_range<rng_t>
128 {
129 return std::ranges::size(rng);
130 }
131
133 constexpr auto size() const
134 requires std::ranges::sized_range<rng_t const>
135 {
136 return std::ranges::size(rng);
137 }
138
140 constexpr auto data()
141 requires std::ranges::contiguous_range<rng_t>
142 {
143 return std::ranges::data(rng);
144 }
145
147 constexpr auto data() const
148 requires std::ranges::contiguous_range<rng_t const>
149 {
150 return std::ranges::data(rng);
151 }
152};
153
157class all_fn : public adaptor_base<all_fn>
158{
159private:
162
164 template <typename t>
165 static constexpr bool decays_to_view = std::ranges::view<std::decay_t<t>>;
166
168 template <typename t>
169 static constexpr bool valid_for_ref_view = requires { std::ranges::ref_view(std::declval<t>()); };
170
172 template <typename t>
173 static constexpr bool valid_for_owning_view = requires { owning_view(std::declval<t>()); };
174
175public:
177
188 template <std::ranges::range rng_t>
189 requires decays_to_view<rng_t> || valid_for_ref_view<rng_t> || valid_for_owning_view<rng_t>
190 static auto impl(rng_t && rng)
191 {
192 if constexpr (decays_to_view<rng_t>)
193 return std::forward<rng_t>(rng);
194 else if constexpr (valid_for_ref_view<rng_t>)
195 return std::ranges::ref_view{std::forward<rng_t>(rng)};
196 else
197 return owning_view{std::forward<rng_t>(rng)};
198 }
199};
200
204inline constexpr auto all = all_fn{};
205
209template <std::ranges::range rng_t>
210using all_t = decltype(all(std::declval<rng_t>()));
211
212} // namespace seqan3::detail
213#endif // __cpp_lib_ranges >= 202110L
Provides seqan3::detail::adaptor_base and seqan3::detail::combined_adaptor.
T begin(T... args)
CRTP-base to simplify the definition of range adaptor closure objects and similar types.
Definition: adaptor_base.hpp:77
constexpr adaptor_base(adaptor_base const &) noexcept=default
Defaulted.
The functor for seqan3::detail::all.
Definition: all_view.hpp:158
static constexpr bool decays_to_view
Checks whether a type is a view.
Definition: all_view.hpp:165
static constexpr bool valid_for_owning_view
Checks whether a type could be used for seqan3::detail::owning_view.
Definition: all_view.hpp:173
static constexpr bool valid_for_ref_view
Checks whether a type could be used for std::ranges::ref_view.
Definition: all_view.hpp:169
static auto impl(rng_t &&rng)
Returns a view that includes all elements of the range argument.
Definition: all_view.hpp:190
A move-only view that takes unique ownership of a range.
Definition: all_view.hpp:42
constexpr rng_t & base() &noexcept
Returns the range.
Definition: all_view.hpp:62
constexpr rng_t && base() &&noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:74
constexpr auto size() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:133
constexpr auto size()
Returns the size of the range.
Definition: all_view.hpp:126
constexpr auto data() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:147
constexpr std::ranges::iterator_t< rng_t > begin()
Return the begin iterator of the range.
Definition: all_view.hpp:86
constexpr auto begin() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:92
constexpr auto data()
Returns the raw data pointer of the range.
Definition: all_view.hpp:140
constexpr std::ranges::sentinel_t< rng_t > end()
Return the end iterator of the range.
Definition: all_view.hpp:99
owning_view()=default
Defaulted.
constexpr rng_t const && base() const &&noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:80
constexpr auto end() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:105
constexpr bool empty()
Checks whether the range is empty.
Definition: all_view.hpp:112
constexpr rng_t const & base() const &noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:68
constexpr bool empty() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: all_view.hpp:119
decltype(all(std::declval< rng_t >())) all_t
Returns the type that results from appying seqan3::detail::all to a range.
Definition: all_view.hpp:210
constexpr auto all
Returns a view that includes all elements of the range argument.
Definition: all_view.hpp:204
constexpr size_t size
The size of a type pack.
Definition: type_pack/traits.hpp:146
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
Provides platform and dependency checks.
Provides type traits for working with templates.