SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
type_traits.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 <seqan3/std/iterator>
16 #include <seqan3/std/ranges>
17 #include <type_traits>
18 
20 #include <seqan3/core/platform.hpp>
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 
39 template <bool const_range, typename range_t>
41 
44 template <bool const_range, typename range_t>
45 using maybe_const_iterator_t = std::ranges::iterator_t<maybe_const_range_t<const_range, range_t>>;
46 
49 template <bool const_v, typename range_t>
50 using maybe_const_sentinel_t = std::ranges::sentinel_t<maybe_const_range_t<const_v, range_t>>;
51 } // namespace seqan3::detail
52 
53 namespace seqan3
54 {
55 
60 // ----------------------------------------------------------------------------
61 // value_type
62 // ----------------------------------------------------------------------------
63 
64 #ifdef SEQAN3_DEPRECATED_310
65 namespace detail
66 {
72 template <std::ranges::input_range rng_t>
74  requires (!std::input_or_output_iterator<rng_t>)
76 struct value_type<rng_t>
77 {
80 };
81 } // namespace seqan3::detail
82 #endif // SEQAN3_DEPRECATED_310
83 
84 // ----------------------------------------------------------------------------
85 // reference
86 // ----------------------------------------------------------------------------
87 
88 #ifdef SEQAN3_DEPRECATED_310
89 namespace detail
90 {
96 template <std::ranges::input_range rng_t>
98  requires (!std::input_or_output_iterator<rng_t>)
100 struct reference<rng_t>
101 {
104 };
105  } // namespace seqan3::detail
106  #endif // SEQAN3_DEPRECATED_310
107 
108 // ----------------------------------------------------------------------------
109 // rvalue_reference
110 // ----------------------------------------------------------------------------
111 
112 #ifdef SEQAN3_DEPRECATED_310
113 namespace detail
114 {
120 template <std::ranges::input_range rng_t>
122  requires (!std::input_or_output_iterator<rng_t>)
124 struct rvalue_reference<rng_t>
125 {
128 };
129 } // namespace seqan3::detail
130 #endif // SEQAN3_DEPRECATED_310
131 
132 // ----------------------------------------------------------------------------
133 // const_reference
134 // ----------------------------------------------------------------------------
135 
136 #ifdef SEQAN3_DEPRECATED_310
137 namespace detail
138 {
144 template <std::ranges::input_range rng_t>
146  requires (!std::input_or_output_iterator<rng_t>)
148 struct const_reference<rng_t>
149 {
152 };
153 } // namespace seqan3::detail
154 #endif // SEQAN3_DEPRECATED_310
155 
156 // ----------------------------------------------------------------------------
157 // difference_type
158 // ----------------------------------------------------------------------------
159 
160 #ifdef SEQAN3_DEPRECATED_310
161 namespace detail
162 {
168 template <std::ranges::range rng_t>
170  requires (!std::input_or_output_iterator<rng_t>)
172 struct difference_type<rng_t>
173 {
176 };
177 } // namespace seqan3::detail
178 #endif // SEQAN3_DEPRECATED_310
179 
180 // ----------------------------------------------------------------------------
181 // size_type
182 // ----------------------------------------------------------------------------
183 
184 #ifdef SEQAN3_DEPRECATED_310
185 namespace detail
186 {
192 template <std::ranges::sized_range rng_t>
194  requires (!std::input_or_output_iterator<rng_t>)
196 struct size_type<rng_t>
197 {
199  using type = decltype(std::ranges::size(std::declval<rng_t &>()));
200 };
201 } // namespace seqan3::detail
202 #endif // SEQAN3_DEPRECATED_310
203 
204 // ----------------------------------------------------------------------------
205 // range_innermost_value
206 // ----------------------------------------------------------------------------
207 
208 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
209 
218 template <typename t>
220  requires detail::has_range_value_type<t>
223 {
225  using type = std::ranges::range_value_t<std::remove_cvref_t<t>>;
226 };
227 
229 template <typename t>
230  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
231 struct range_innermost_value<t>
232 {
234 };
236 
239 template <typename t>
241 
242 // ----------------------------------------------------------------------------
243 // range_dimension_v
244 // ----------------------------------------------------------------------------
245 
246 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
247 
256 template <typename t>
258  requires detail::has_range_value_type<t>
260 constexpr size_t range_dimension_v = 1;
261 
263 template <typename t>
264  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
265 constexpr size_t range_dimension_v<t> = range_dimension_v<std::ranges::range_value_t<std::remove_cvref_t<t>>> + 1;
267 
268 // ----------------------------------------------------------------------------
269 // range_compatible [DEPRECATED]
270 // ----------------------------------------------------------------------------
271 
272 #ifdef SEQAN3_DEPRECATED_310
279 namespace deprecated
280 {
281 template <typename t1, typename t2>
282 SEQAN3_CONCEPT range_compatible_concept = requires (t1, t2)
283 {
284  requires (range_dimension_v<t1> == range_dimension_v<t2>);
285 
286  requires std::is_same_v<range_innermost_value_t<t1>, range_innermost_value_t<t2>>;
287 };
288 } // namespace seqan3::deprecated
289 
290 template <typename t1, typename t2>
291 SEQAN3_DEPRECATED_310 constexpr bool range_compatible = deprecated::range_compatible_concept<t1, t2>;
293 #endif // SEQAN3_DEPRECATED_310
294 
296 
297 } // namespace seqan3
std::ranges::sentinel_t< maybe_const_range_t< const_v, range_t > > maybe_const_sentinel_t
Returns the const sentinel of range_t if const_range is true; otherwise the non-const sentinel.
Definition: type_traits.hpp:50
constexpr size_t range_dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t (type trait).
Definition: type_traits.hpp:260
std::ranges::iterator_t< maybe_const_range_t< const_range, range_t > > maybe_const_iterator_t
Returns the const iterator of range_t if const_range is true; otherwise the non-const iterator.
Definition: type_traits.hpp:45
typename range_innermost_value< t >::type range_innermost_value_t
Shortcut for seqan3::range_innermost_value (transformation_trait shortcut).
Definition: type_traits.hpp:240
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:150
Two types are "compatible" if their seqan3::range_dimension_v and their seqan3::range_innermost_value...
Provides various transformation traits for use on iterators.
Provides C++20 additions to the <iterator> header.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
typename value_type< t >::type value_type_t
This is helper structure to deprecate seqan3::value_type_t and will be removed before SeqAn 3....
Definition: pre.hpp:37
typename difference_type< t >::type difference_type_t
This is helper structure to deprecate seqan3::difference_type_t and will be removed before SeqAn 3....
Definition: pre.hpp:233
typename reference< t >::type reference_t
This is helper structure to deprecate seqan3::reference_t and will be removed before SeqAn 3....
Definition: pre.hpp:85
typename rvalue_reference< t >::type rvalue_reference_t
This is helper structure to deprecate seqan3::rvalue_reference_t and will be removed before SeqAn 3....
Definition: pre.hpp:133
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides platform and dependency checks.
#define SEQAN3_DEPRECATED_310
Deprecation message for SeqAn 3.1.0 release.
Definition: platform.hpp:202
Adaptations of concepts from the Ranges TS.
This is helper structure to deprecate seqan3::const_reference and will be removed before SeqAn 3....
Definition: pre.hpp:177
difference_type_t< std::ranges::iterator_t< rng_t > > type
Return the difference_type member definition from the queried type's iterator.
Definition: type_traits.hpp:175
This is helper structure to deprecate seqan3::difference_type and will be removed before SeqAn 3....
Definition: pre.hpp:229
reference_t< std::ranges::iterator_t< rng_t > > type
Return the reference member definition from the queried type's iterator.
Definition: type_traits.hpp:103
This is helper structure to deprecate seqan3::reference and will be removed before SeqAn 3....
Definition: pre.hpp:81
rvalue_reference_t< std::ranges::iterator_t< rng_t > > type
Return the rvalue_reference member definition from the queried type's iterator.
Definition: type_traits.hpp:127
This is helper structure to deprecate seqan3::rvalue_reference and will be removed before SeqAn 3....
Definition: pre.hpp:129
decltype(std::ranges::size(std::declval< rng_t & >())) type
Return the size_type as returned by the size function.
Definition: type_traits.hpp:199
This is helper structure to deprecate seqan3::size_type and will be removed before SeqAn 3....
Definition: pre.hpp:279
value_type_t< std::ranges::iterator_t< rng_t > > type
Return the value_type member definition from the queried type's iterator.
Definition: type_traits.hpp:79
This is helper structure to deprecate seqan3::value_type and will be removed before SeqAn 3....
Definition: pre.hpp:33
Recursively determines the value_type on containers and/or iterators.
Definition: type_traits.hpp:223
std::ranges::range_value_t< std::remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: type_traits.hpp:225
Provides various type traits on generic types.
Provides various transformation trait base templates and shortcuts.