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-2021, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2021, 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>
22 #ifdef SEQAN3_DEPRECATED_310
24 #endif // SEQAN3_DEPRECATED_310
25 
26 // TODO(h-2): add innermost_reference instead of or addition to range_innermost_value?
27 
28 //NOTE(h-2): for the range overloads we explicitly forbid that the type is iteratoer
29 // because some types are actually both (e.g. std::directory_iterator)
30 
31 namespace seqan3::detail
32 {
33 
35 template <typename t>
36 SEQAN3_CONCEPT has_range_value_type = requires { typename std::ranges::range_value_t<std::remove_cvref_t<t>>; };
38 
41 template <bool const_range, typename range_t>
43 
46 template <bool const_range, typename range_t>
47 using maybe_const_iterator_t = std::ranges::iterator_t<maybe_const_range_t<const_range, range_t>>;
48 
51 template <bool const_v, typename range_t>
52 using maybe_const_sentinel_t = std::ranges::sentinel_t<maybe_const_range_t<const_v, range_t>>;
53 } // namespace seqan3::detail
54 
55 namespace seqan3
56 {
57 
62 // ----------------------------------------------------------------------------
63 // value_type
64 // ----------------------------------------------------------------------------
65 
66 #ifdef SEQAN3_DEPRECATED_310
67 namespace detail
68 {
74 template <std::ranges::input_range rng_t>
76  requires (!std::input_or_output_iterator<rng_t>)
78 struct value_type<rng_t>
79 {
81  using type = value_type_t<std::ranges::iterator_t<rng_t>>;
82 };
83 } // namespace seqan3::detail
84 #endif // SEQAN3_DEPRECATED_310
85 
86 // ----------------------------------------------------------------------------
87 // reference
88 // ----------------------------------------------------------------------------
89 
90 #ifdef SEQAN3_DEPRECATED_310
91 namespace detail
92 {
98 template <std::ranges::input_range rng_t>
100  requires (!std::input_or_output_iterator<rng_t>)
102 struct reference<rng_t>
103 {
105  using type = reference_t<std::ranges::iterator_t<rng_t>>;
106 };
107  } // namespace seqan3::detail
108  #endif // SEQAN3_DEPRECATED_310
109 
110 // ----------------------------------------------------------------------------
111 // rvalue_reference
112 // ----------------------------------------------------------------------------
113 
114 #ifdef SEQAN3_DEPRECATED_310
115 namespace detail
116 {
122 template <std::ranges::input_range rng_t>
124  requires (!std::input_or_output_iterator<rng_t>)
126 struct rvalue_reference<rng_t>
127 {
129  using type = rvalue_reference_t<std::ranges::iterator_t<rng_t>>;
130 };
131 } // namespace seqan3::detail
132 #endif // SEQAN3_DEPRECATED_310
133 
134 // ----------------------------------------------------------------------------
135 // const_reference
136 // ----------------------------------------------------------------------------
137 
138 #ifdef SEQAN3_DEPRECATED_310
139 namespace detail
140 {
146 template <std::ranges::input_range rng_t>
148  requires (!std::input_or_output_iterator<rng_t>)
150 struct const_reference<rng_t>
151 {
154 };
155 } // namespace seqan3::detail
156 #endif // SEQAN3_DEPRECATED_310
157 
158 // ----------------------------------------------------------------------------
159 // difference_type
160 // ----------------------------------------------------------------------------
161 
162 #ifdef SEQAN3_DEPRECATED_310
163 namespace detail
164 {
170 template <std::ranges::range rng_t>
172  requires (!std::input_or_output_iterator<rng_t>)
174 struct difference_type<rng_t>
175 {
177  using type = difference_type_t<std::ranges::iterator_t<rng_t>>;
178 };
179 } // namespace seqan3::detail
180 #endif // SEQAN3_DEPRECATED_310
181 
182 // ----------------------------------------------------------------------------
183 // size_type
184 // ----------------------------------------------------------------------------
185 
186 #ifdef SEQAN3_DEPRECATED_310
187 namespace detail
188 {
194 template <std::ranges::sized_range rng_t>
196  requires (!std::input_or_output_iterator<rng_t>)
198 struct size_type<rng_t>
199 {
201  using type = decltype(std::ranges::size(std::declval<rng_t &>()));
202 };
203 } // namespace seqan3::detail
204 #endif // SEQAN3_DEPRECATED_310
205 
206 // ----------------------------------------------------------------------------
207 // range_innermost_value
208 // ----------------------------------------------------------------------------
209 
210 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
211 
220 template <typename t>
222  requires detail::has_range_value_type<t>
225 {
227  using type = std::ranges::range_value_t<std::remove_cvref_t<t>>;
228 };
229 
231 template <typename t>
232  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
233 struct range_innermost_value<t>
234 {
236 };
238 
241 template <typename t>
243 
244 // ----------------------------------------------------------------------------
245 // range_dimension_v
246 // ----------------------------------------------------------------------------
247 
248 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
249 
258 template <typename t>
260  requires detail::has_range_value_type<t>
262 constexpr size_t range_dimension_v = 1;
263 
265 template <typename t>
266  requires detail::has_range_value_type<t> && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
267 constexpr size_t range_dimension_v<t> = range_dimension_v<std::ranges::range_value_t<std::remove_cvref_t<t>>> + 1;
269 
270 // ----------------------------------------------------------------------------
271 // range_compatible [DEPRECATED]
272 // ----------------------------------------------------------------------------
273 
274 #ifdef SEQAN3_DEPRECATED_310
281 namespace deprecated
282 {
283 template <typename t1, typename t2>
284 SEQAN3_CONCEPT range_compatible_concept = requires (t1, t2)
285 {
286  requires (range_dimension_v<t1> == range_dimension_v<t2>);
287 
288  requires std::is_same_v<range_innermost_value_t<t1>, range_innermost_value_t<t2>>;
289 };
290 } // namespace seqan3::deprecated
291 
292 template <typename t1, typename t2>
293 SEQAN3_DEPRECATED_310 constexpr bool range_compatible = deprecated::range_compatible_concept<t1, t2>;
295 #endif // SEQAN3_DEPRECATED_310
296 
298 
299 } // namespace seqan3
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:262
typename range_innermost_value< t >::type range_innermost_value_t
Shortcut for seqan3::range_innermost_value (transformation_trait shortcut).
Definition: type_traits.hpp:242
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:151
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 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:203
Adaptations of concepts from the Ranges TS.
Recursively determines the value_type on containers and/or iterators.
Definition: type_traits.hpp:225
std::ranges::range_value_t< std::remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: type_traits.hpp:227
Provides various type traits on generic types.
Provides various transformation trait base templates and shortcuts.