SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
core/range/type_traits.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 <iterator>
16 #include <ranges>
17 #include <type_traits>
18 
20 #include <seqan3/core/platform.hpp>
22 
23 // TODO(h-2): add innermost_reference instead of or addition to range_innermost_value?
24 
25 //NOTE(h-2): for the range overloads we explicitly forbid that the type is iteratoer
26 // because some types are actually both (e.g. std::directory_iterator)
27 
28 namespace seqan3::detail
29 {
30 
32 template <typename t>
33 concept has_range_value_type = requires { typename std::ranges::range_value_t<std::remove_cvref_t<t>>; };
35 
38 template <bool const_range, typename range_t>
40 
43 template <bool const_range, typename range_t>
44 using maybe_const_iterator_t = std::ranges::iterator_t<maybe_const_range_t<const_range, range_t>>;
45 
48 template <bool const_v, typename range_t>
49 using maybe_const_sentinel_t = std::ranges::sentinel_t<maybe_const_range_t<const_v, range_t>>;
50 
53 template <typename unary_predicate_fn_t, typename urng_t>
54 concept indirect_unary_predicate_on_range =
55  std::ranges::range<urng_t> && std::indirect_unary_predicate<unary_predicate_fn_t, std::ranges::iterator_t<urng_t>>;
57 } // namespace seqan3::detail
58 
59 namespace seqan3
60 {
61 
62 // ----------------------------------------------------------------------------
63 // range_innermost_value
64 // ----------------------------------------------------------------------------
65 
76 template <typename t>
77  requires detail::has_range_value_type<t>
79 {
81  using type = std::ranges::range_value_t<std::remove_cvref_t<t>>;
82 };
83 
85 template <typename t>
86  requires detail::has_range_value_type<t>
87  && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
88 struct range_innermost_value<t>
89 {
91 };
93 
97 template <typename t>
99 
100 // ----------------------------------------------------------------------------
101 // range_dimension_v
102 // ----------------------------------------------------------------------------
103 
113 template <typename t>
114  requires detail::has_range_value_type<t>
115 constexpr size_t range_dimension_v = 1;
116 
118 template <typename t>
119  requires detail::has_range_value_type<t>
120  && detail::has_range_value_type<std::ranges::range_value_t<std::remove_cvref_t<t>>>
121 constexpr size_t range_dimension_v<t> = range_dimension_v<std::ranges::range_value_t<std::remove_cvref_t<t>>> + 1;
123 
124 } // namespace seqan3
Provides various type traits on generic types.
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
typename range_innermost_value< t >::type range_innermost_value_t
Shortcut for seqan3::range_innermost_value (transformation_trait shortcut).
Definition: core/range/type_traits.hpp:98
requires constexpr detail::has_range_value_type< t > size_t range_dimension_v
Returns the number of times you can call seqan3::value_type_t recursively on t (type trait).
Definition: core/range/type_traits.hpp:115
Provides various transformation traits for use on iterators.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Provides platform and dependency checks.
The <ranges> header from C++20's standard library.
Recursively determines the value_type on containers and/or iterators.
Definition: core/range/type_traits.hpp:79
std::ranges::range_value_t< std::remove_cvref_t< t > > type
The return type (recursion not shown).
Definition: core/range/type_traits.hpp:81