SeqAn3
range.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <type_traits>
43 
44 #include <range/v3/utility/iterator_traits.hpp>
45 #include <range/v3/range_traits.hpp>
46 
47 #include <seqan3/core/platform.hpp>
52 #include <seqan3/std/ranges>
53 #include <seqan3/std/iterator>
54 
55 // TODO(h-2): add innermost_reference instead of or addition to innermost_value_type?
56 
57 //NOTE(h-2): for the range overloads we explicitly forbid that the type is iteratoer
58 // because some types are actually both (e.g. std::directory_iterator)
59 
60 namespace seqan3::detail
61 {
62 
64 template <typename t>
65 concept has_value_type = requires { typename value_type_t<remove_cvref_t<t>>; };
67 
68 } // namespace seqan3::detail
69 
70 namespace seqan3
71 {
72 
77 // ----------------------------------------------------------------------------
78 // value_type
79 // ----------------------------------------------------------------------------
80 
84 template <std::ranges::InputRange rng_t>
86  requires !std::Iterator<rng_t>
88 struct value_type<rng_t>
89 {
92 };
93 
94 // ----------------------------------------------------------------------------
95 // reference
96 // ----------------------------------------------------------------------------
97 
101 template <std::ranges::InputRange rng_t>
103  requires !std::Iterator<rng_t>
105 struct reference<rng_t>
106 {
109 };
110 
111 // ----------------------------------------------------------------------------
112 // rvalue_reference
113 // ----------------------------------------------------------------------------
114 
118 template <std::ranges::InputRange rng_t>
120  requires !std::Iterator<rng_t>
122 struct rvalue_reference<rng_t>
123 {
126 };
127 
128 // ----------------------------------------------------------------------------
129 // const_reference
130 // ----------------------------------------------------------------------------
131 
135 template <std::ranges::InputRange rng_t>
137  requires !std::Iterator<rng_t>
139 struct const_reference<rng_t>
140 {
143 };
144 
145 // ----------------------------------------------------------------------------
146 // difference_type
147 // ----------------------------------------------------------------------------
148 
152 template <std::ranges::Range rng_t>
154  requires !std::Iterator<rng_t>
156 struct difference_type<rng_t>
157 {
160 };
161 
162 // ----------------------------------------------------------------------------
163 // size_type
164 // ----------------------------------------------------------------------------
165 
169 template <std::ranges::SizedRange rng_t>
171  requires !std::Iterator<rng_t>
173 struct size_type<rng_t>
174 {
176  using type = decltype(size(std::declval<rng_t &>()));
177 };
178 
179 // ----------------------------------------------------------------------------
180 // innermost_value_type
181 // ----------------------------------------------------------------------------
182 
183 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
184 
192 template <typename t>
194  requires detail::has_value_type<t>
197 {
200 };
201 
203 template <typename t>
204  requires detail::has_value_type<t> && detail::has_value_type<value_type_t<remove_cvref_t<t>>>
205 struct innermost_value_type<t>
206 {
208 };
210 
212 template <typename t>
214 
215 // ----------------------------------------------------------------------------
216 // dimension_v
217 // ----------------------------------------------------------------------------
218 
219 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
220 
229 template <typename t>
231  requires detail::has_value_type<t>
233 constexpr size_t dimension_v = 1;
234 
236 template <typename t>
237  requires detail::has_value_type<t> && detail::has_value_type<value_type_t<remove_cvref_t<t>>>
238 constexpr size_t dimension_v<t> = dimension_v<value_type_t<remove_cvref_t<t>>> + 1;
240 
241 // ----------------------------------------------------------------------------
242 // compatible_concept
243 // ----------------------------------------------------------------------------
244 
245 //NOTE(h-2): this could be moved to a separate file, because it also applies to iterators
246 
258 template <typename t1, typename t2>
260 concept compatible_concept = requires (t1, t2)
261 {
262  requires (dimension_v<t1> == dimension_v<t2>);
263 
264  requires std::is_same_v<innermost_value_type_t<t1>, innermost_value_type_t<t2>>;
265 };
267 
269 
270 } // namespace seqan3
value_type_t< std::ranges::iterator_t< rng_t > > type
Return the value_type member definition from the queried type&#39;s iterator.
Definition: range.hpp:91
decltype(size(std::declval< rng_t & >())) type
Return the size_type as returned by the size function.
Definition: range.hpp:176
value_type_t< remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: range.hpp:199
Contains platform and dependency checks.
typename innermost_value_type< t >::type innermost_value_type_t
Shortcut for seqan3::innermost_value_type.
Definition: range.hpp:213
Provides C++20 additions to the <iterator> header.
Contains various shortcuts for common std::ranges functions.
rvalue_reference_t< std::ranges::iterator_t< rng_t > > type
Return the rvalue_reference member definition from the queried type&#39;s iterator.
Definition: range.hpp:125
reference_t< std::ranges::iterator_t< rng_t > > type
Return the reference member definition from the queried type&#39;s iterator.
Definition: range.hpp:108
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Two types are "compatible" if their seqan3::dimension_v and their seqan3::innermost_value_type_t are ...
typename rvalue_reference< t >::type rvalue_reference_t
Type metafunction shortcut for seqan3::rvalue_reference.
Definition: pre.hpp:124
Type metafunction that returns the difference_type of another type [metafunction declaration].
Definition: pre.hpp:172
Provides various metafunctions base templates and shortcuts.
Recursively determines the value_type on containers and/or iterators [Type metafunction].
Definition: range.hpp:196
constexpr size_t dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t [Value metafunction]...
Definition: range.hpp:233
Adaptations of concepts from the Ranges TS.
Type metafunction that returns the size_type of another type [metafunction declaration].
Definition: pre.hpp:198
typename difference_type< t >::type difference_type_t
Type metafunction shortcut for seqan3::difference_type.
Definition: pre.hpp:178
The Iterator concept forms the basis of the iterator concept taxonomy; every iterator satisfies the I...
Definition: aligned_sequence_concept.hpp:288
Provides C++20 additions to the type_traits header.
Provides various metafunctions on generic types.
Type metafunction that returns the const_reference of another type [metafunction declaration].
Definition: pre.hpp:146
Type metafunction that returns the rvalue_reference of another type [metafunction declaration]...
Definition: pre.hpp:118
typename reference< t >::type reference_t
Type metafunction shortcut for seqan3::reference.
Definition: pre.hpp:98
Type metafunction that returns the reference of another type [metafunction declaration].
Definition: pre.hpp:92
typename value_type< t >::type value_type_t
Type metafunction shortcut for seqan3::value_type.
Definition: pre.hpp:72
Provides various metafunctions for use on iterators.
Type metafunction that returns the value_type of another type [metafunction declaration].
Definition: pre.hpp:66
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:142
difference_type_t< std::ranges::iterator_t< rng_t > > type
Return the difference_type member definition from the queried type&#39;s iterator.
Definition: range.hpp:159