SeqAn3  3.0.1
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>
22 #include <seqan3/std/ranges>
23 #include <seqan3/std/iterator>
24 
25 // TODO(h-2): add innermost_reference instead of or addition to innermost_value_type?
26 
27 //NOTE(h-2): for the range overloads we explicitly forbid that the type is iteratoer
28 // because some types are actually both (e.g. std::directory_iterator)
29 
30 namespace seqan3::detail
31 {
32 
34 template <typename t>
35 SEQAN3_CONCEPT has_value_type = requires { typename value_type_t<remove_cvref_t<t>>; };
37 
38 } // namespace seqan3::detail
39 
40 namespace seqan3
41 {
42 
47 // ----------------------------------------------------------------------------
48 // value_type
49 // ----------------------------------------------------------------------------
50 
55 template <std::ranges::input_range rng_t>
57  requires !std::input_or_output_iterator<rng_t>
59 struct value_type<rng_t>
60 {
63 };
64 
65 // ----------------------------------------------------------------------------
66 // reference
67 // ----------------------------------------------------------------------------
68 
73 template <std::ranges::input_range rng_t>
75  requires !std::input_or_output_iterator<rng_t>
77 struct reference<rng_t>
78 {
81 };
82 
83 // ----------------------------------------------------------------------------
84 // rvalue_reference
85 // ----------------------------------------------------------------------------
86 
91 template <std::ranges::input_range rng_t>
93  requires !std::input_or_output_iterator<rng_t>
95 struct rvalue_reference<rng_t>
96 {
99 };
100 
101 // ----------------------------------------------------------------------------
102 // const_reference
103 // ----------------------------------------------------------------------------
104 
109 template <std::ranges::input_range rng_t>
111  requires !std::input_or_output_iterator<rng_t>
113 struct const_reference<rng_t>
114 {
117 };
118 
119 // ----------------------------------------------------------------------------
120 // difference_type
121 // ----------------------------------------------------------------------------
122 
127 template <std::ranges::range rng_t>
129  requires !std::input_or_output_iterator<rng_t>
131 struct difference_type<rng_t>
132 {
135 };
136 
137 // ----------------------------------------------------------------------------
138 // size_type
139 // ----------------------------------------------------------------------------
140 
145 template <std::ranges::sized_range rng_t>
147  requires !std::input_or_output_iterator<rng_t>
149 struct size_type<rng_t>
150 {
152  using type = decltype(size(std::declval<rng_t &>()));
153 };
154 
155 // ----------------------------------------------------------------------------
156 // innermost_value_type
157 // ----------------------------------------------------------------------------
158 
159 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
160 
169 template <typename t>
171  requires detail::has_value_type<t>
174 {
177 };
178 
180 template <typename t>
181  requires detail::has_value_type<t> && detail::has_value_type<value_type_t<remove_cvref_t<t>>>
182 struct innermost_value_type<t>
183 {
185 };
187 
190 template <typename t>
192 
193 // ----------------------------------------------------------------------------
194 // dimension_v
195 // ----------------------------------------------------------------------------
196 
197 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
198 
207 template <typename t>
209  requires detail::has_value_type<t>
211 constexpr size_t dimension_v = 1;
212 
214 template <typename t>
215  requires detail::has_value_type<t> && detail::has_value_type<value_type_t<remove_cvref_t<t>>>
216 constexpr size_t dimension_v<t> = dimension_v<value_type_t<remove_cvref_t<t>>> + 1;
218 
219 // ----------------------------------------------------------------------------
220 // compatible
221 // ----------------------------------------------------------------------------
222 
223 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
224 
236 template <typename t1, typename t2>
238 SEQAN3_CONCEPT compatible = requires (t1, t2)
239 {
240  requires (dimension_v<t1> == dimension_v<t2>);
241 
242  requires std::is_same_v<innermost_value_type_t<t1>, innermost_value_type_t<t2>>;
243 };
245 
247 
248 } // namespace seqan3
seqan3::difference_type_t
typename difference_type< t >::type difference_type_t
Shortcut for seqan3::difference_type (transformation_trait shortcut).
Definition: pre.hpp:166
shortcuts.hpp
Provides various shortcuts for common std::ranges functions.
pre.hpp
Provides various transformation trait base templates and shortcuts.
seqan3::reference_t
typename reference< t >::type reference_t
Shortcut for seqan3::reference (transformation_trait shortcut).
Definition: pre.hpp:77
iterator
Provides C++20 additions to the <iterator> header.
basic.hpp
Provides various type traits on generic types.
seqan3::rvalue_reference< rng_t >::type
rvalue_reference_t< std::ranges::iterator_t< rng_t > > type
Return the rvalue_reference member definition from the queried type's iterator.
Definition: range.hpp:98
compatible
Two types are "compatible" if their seqan3::dimension_v and their seqan3::innermost_value_type_t are ...
seqan3::const_reference< rng_t >::type
reference_t< std::ranges::iterator_t< rng_t const > > type
Resolves to the reference type of the const_iterator of t (not the const iterator!...
Definition: range.hpp:116
seqan3::value_type< rng_t >::type
value_type_t< std::ranges::iterator_t< rng_t > > type
Return the value_type member definition from the queried type's iterator.
Definition: range.hpp:62
seqan3::value_type
Exposes the value_type of another type.
Definition: pre.hpp:41
seqan3::innermost_value_type
Recursively determines the value_type on containers and/or iterators.
Definition: range.hpp:173
seqan3::value_type_t
typename value_type< t >::type value_type_t
Shortcut for seqan3::value_type (transformation_trait shortcut).
Definition: pre.hpp:48
seqan3::difference_type
Exposes the difference_type of another type.
Definition: pre.hpp:159
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::innermost_value_type::type
value_type_t< remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: range.hpp:176
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
seqan3::reference
Exposes the reference of another type.
Definition: pre.hpp:70
seqan3::size_type
Exposes the size_type of another type.
Definition: pre.hpp:188
seqan3::const_reference
Exposes the const_reference of another type.
Definition: pre.hpp:130
ranges
Adaptations of concepts from the Ranges TS.
seqan3::dimension_v
constexpr size_t dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t (type trait).
Definition: range.hpp:211
platform.hpp
Provides platform and dependency checks.
seqan3::reference< rng_t >::type
reference_t< std::ranges::iterator_t< rng_t > > type
Return the reference member definition from the queried type's iterator.
Definition: range.hpp:80
seqan3::size_type< rng_t >::type
decltype(size(std::declval< rng_t & >())) type
Return the size_type as returned by the size function.
Definition: range.hpp:152
seqan3::innermost_value_type_t
typename innermost_value_type< t >::type innermost_value_type_t
Shortcut for seqan3::innermost_value_type (transformation_trait shortcut).
Definition: range.hpp:191
seqan3::rvalue_reference_t
typename rvalue_reference< t >::type rvalue_reference_t
Shortcut for seqan3::rvalue_reference (transformation_trait shortcut).
Definition: pre.hpp:106
seqan3::difference_type< rng_t >::type
difference_type_t< std::ranges::iterator_t< rng_t > > type
Return the difference_type member definition from the queried type's iterator.
Definition: range.hpp:134
seqan3::rvalue_reference
Exposes the rvalue_reference of another type.
Definition: pre.hpp:99