SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
range.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <type_traits>
16 
17 #include <seqan3/core/platform.hpp>
21 #include <seqan3/std/ranges>
22 #include <seqan3/std/iterator>
23 
24 // TODO(h-2): add innermost_reference instead of or addition to range_innermost_value?
25 
26 //NOTE(h-2): for the range overloads we explicitly forbid that the type is iteratoer
27 // because some types are actually both (e.g. std::directory_iterator)
28 
29 namespace seqan3::detail
30 {
31 
33 template <typename t>
34 SEQAN3_CONCEPT has_range_value_type = requires { typename std::ranges::range_value_t<std::remove_cvref_t<t>>; };
36 
37 } // namespace seqan3::detail
38 
39 namespace seqan3
40 {
41 
46 // ----------------------------------------------------------------------------
47 // value_type
48 // ----------------------------------------------------------------------------
49 
50 #ifdef SEQAN3_DEPRECATED_310
51 namespace detail
52 {
58 template <std::ranges::input_range rng_t>
60  requires (!std::input_or_output_iterator<rng_t>)
62 struct value_type<rng_t>
63 {
65  using type = value_type_t<std::ranges::iterator_t<rng_t>>;
66 };
67 } // namespace seqan3::detail
68 #endif // SEQAN3_DEPRECATED_310
69 
70 // ----------------------------------------------------------------------------
71 // reference
72 // ----------------------------------------------------------------------------
73 
74 #ifdef SEQAN3_DEPRECATED_310
75 namespace detail
76 {
82 template <std::ranges::input_range rng_t>
84  requires (!std::input_or_output_iterator<rng_t>)
86 struct reference<rng_t>
87 {
89  using type = reference_t<std::ranges::iterator_t<rng_t>>;
90 };
91  } // namespace seqan3::detail
92  #endif // SEQAN3_DEPRECATED_310
93 
94 // ----------------------------------------------------------------------------
95 // rvalue_reference
96 // ----------------------------------------------------------------------------
97 
98 #ifdef SEQAN3_DEPRECATED_310
99 namespace detail
100 {
106 template <std::ranges::input_range rng_t>
108  requires (!std::input_or_output_iterator<rng_t>)
110 struct rvalue_reference<rng_t>
111 {
113  using type = rvalue_reference_t<std::ranges::iterator_t<rng_t>>;
114 };
115 } // namespace seqan3::detail
116 #endif // SEQAN3_DEPRECATED_310
117 
118 // ----------------------------------------------------------------------------
119 // const_reference
120 // ----------------------------------------------------------------------------
121 
122 #ifdef SEQAN3_DEPRECATED_310
123 namespace detail
124 {
130 template <std::ranges::input_range rng_t>
132  requires (!std::input_or_output_iterator<rng_t>)
134 struct const_reference<rng_t>
135 {
138 };
139 } // namespace seqan3::detail
140 #endif // SEQAN3_DEPRECATED_310
141 
142 // ----------------------------------------------------------------------------
143 // difference_type
144 // ----------------------------------------------------------------------------
145 
146 #ifdef SEQAN3_DEPRECATED_310
147 namespace detail
148 {
154 template <std::ranges::range rng_t>
156  requires (!std::input_or_output_iterator<rng_t>)
158 struct difference_type<rng_t>
159 {
161  using type = difference_type_t<std::ranges::iterator_t<rng_t>>;
162 };
163 } // namespace seqan3::detail
164 #endif // SEQAN3_DEPRECATED_310
165 
166 // ----------------------------------------------------------------------------
167 // size_type
168 // ----------------------------------------------------------------------------
169 
170 #ifdef SEQAN3_DEPRECATED_310
171 namespace detail
172 {
178 template <std::ranges::sized_range rng_t>
180  requires (!std::input_or_output_iterator<rng_t>)
182 struct size_type<rng_t>
183 {
185  using type = decltype(std::ranges::size(std::declval<rng_t &>()));
186 };
187 } // namespace seqan3::detail
188 #endif // SEQAN3_DEPRECATED_310
189 
190 // ----------------------------------------------------------------------------
191 // range_innermost_value
192 // ----------------------------------------------------------------------------
193 
194 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
195 
204 template <typename t>
206  requires detail::has_range_value_type<t>
209 {
211  using type = std::ranges::range_value_t<std::remove_cvref_t<t>>;
212 };
213 
215 template <typename t>
216  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
217 struct range_innermost_value<t>
218 {
220 };
222 
225 template <typename t>
227 
228 // ----------------------------------------------------------------------------
229 // range_dimension_v
230 // ----------------------------------------------------------------------------
231 
232 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
233 
242 template <typename t>
244  requires detail::has_range_value_type<t>
246 constexpr size_t range_dimension_v = 1;
247 
249 template <typename t>
250  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
251 constexpr size_t range_dimension_v<t> = range_dimension_v<std::ranges::range_value_t<std::remove_cvref_t<t>>> + 1;
253 
254 // ----------------------------------------------------------------------------
255 // range_compatible
256 // ----------------------------------------------------------------------------
257 
258 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
259 
271 template <typename t1, typename t2>
273 SEQAN3_CONCEPT range_compatible = requires (t1, t2)
274 {
275  requires (range_dimension_v<t1> == range_dimension_v<t2>);
276 
277  requires std::is_same_v<range_innermost_value_t<t1>, range_innermost_value_t<t2>>;
278 };
280 
282 
283 } // namespace seqan3
seqan3::range_innermost_value::type
std::ranges::range_value_t< std::remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: range.hpp:211
pre.hpp
Provides various transformation trait base templates and shortcuts.
iterator
Provides C++20 additions to the <iterator> header.
seqan3::range_innermost_value_t
typename range_innermost_value< t >::type range_innermost_value_t
Shortcut for seqan3::range_innermost_value (transformation_trait shortcut).
Definition: range.hpp:226
basic.hpp
Provides various type traits on generic types.
range_compatible
Two types are "compatible" if their seqan3::range_dimension_v and their seqan3::range_innermost_value...
seqan3::range_dimension_v
constexpr size_t range_dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t (type trait).
Definition: range.hpp:246
seqan3::range_innermost_value
Recursively determines the value_type on containers and/or iterators.
Definition: range.hpp:209
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
std::iter_reference_t
iterator.hpp
Provides various transformation traits for use on iterators.
seqan3::pack_traits::size
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:116
ranges
Adaptations of concepts from the Ranges TS.
platform.hpp
Provides platform and dependency checks.