SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
concept.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/concepts>
16 #include <tuple>
17 #include <type_traits>
18 
23 
24 namespace seqan3::detail
25 {
26 
33 template <typename tuple_t>
34 SEQAN3_CONCEPT tuple_size = requires (tuple_t v)
35 {
36  SEQAN3_RETURN_TYPE_CONSTRAINT(std::tuple_size<tuple_t>::value, std::convertible_to, size_t);
37 };
39 
46 template <typename tuple_t>
47 SEQAN3_CONCEPT tuple_get = requires (tuple_t & v, tuple_t const & v_c)
48 {
49  requires std::tuple_size_v<tuple_t> > 0;
50 
51  typename std::tuple_element<0, tuple_t>::type;
52 
53  SEQAN3_RETURN_TYPE_CONSTRAINT(get<0>(v), std::convertible_to, typename std::tuple_element<0, tuple_t>::type);
54 // requires weakly_assignable_from<decltype(get<0>(v)), typename std::tuple_element<0, tuple_t>::type>;
55  //TODO check that the previous returns something that can be assigned to
56  // unfortunately std::assignable_from requires lvalue-reference, but we want to accept xvalues too (returned
57  // proxies)
58  SEQAN3_RETURN_TYPE_CONSTRAINT(get<0>(v_c), std::convertible_to, typename std::tuple_element<0, tuple_t>::type);
60  std::convertible_to, typename std::tuple_element<0, tuple_t>::type);
61  // TODO: The return type for std::tuple is wrong until gcc-8.0, for gcc > 8.0 this is fixed.
62  { get<0>(std::move(v_c)) };// -> typename std::tuple_element<0, tuple_t>::type const &&;
63  // SEQAN3_RETURN_TYPE_CONSTRAINT(get<0>(std::move(v_c)),
64  // std::convertible_to, typename std::tuple_element<0, tuple_t>::type const &&);
65 };
67 
77 template <typename state_t, typename element_t>
79 {
84 };
85 
93 template <detail::tuple_size tuple_t>
95 {
96 protected:
97 
99  template <size_t ... Is>
101  {
103  }
104 
105 public:
107  using type = decltype(invoke_to_type_list(std::make_index_sequence<std::tuple_size<tuple_t>::value>{}));
108 };
109 
115 template <detail::tuple_size tuple_t>
117 
118 } // namespace seqan3::detail
119 
120 namespace seqan3
121 {
122 
123 // ----------------------------------------------------------------------------
124 // tuple_like
125 // ----------------------------------------------------------------------------
126 
176 template <typename t>
177 SEQAN3_CONCEPT tuple_like = detail::tuple_size<std::remove_reference_t<t>> && requires(t v)
178 {
180 
181  // NOTE(rrahn): To check the full tuple_concept including the get interface and the std::totally_ordered
182  // we need to make some assumptions. In general these checks can only be executed if the tuple is not
183  // empty. Furthermore, the std::totally_ordered can only be checked if all elements in the
184  // tuple are strict_totally_ordered. This is done, by the fold expression in the second part.
185  requires (std::tuple_size<std::remove_reference_t<t>>::value == 0) ||
186  (detail::tuple_get<std::remove_cvref_t<t>> &&
187  (!meta::fold<detail::tuple_type_list_t<std::remove_cvref_t<t>>,
189  meta::quote_trait<detail::models_strict_totally_ordered>>::value ||
190  std::totally_ordered<std::remove_cvref_t<t>>));
191 };
193 
205 template <typename t>
206 SEQAN3_CONCEPT pair_like = tuple_like<t> && std::tuple_size_v<std::remove_reference_t<t>> == 2;
208 
209 } // namespace seqan3
The Concepts library.
Provides type traits for working with templates.
meta::list< types... > type_list
Type that contains multiple types, an alias for meta::list.
Definition: type_list.hpp:31
typename tuple_type_list< tuple_t >::type tuple_type_list_t
Helper type for seqan3::detail::tuple_type_list.
Definition: concept.hpp:116
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:70
Subconcept definition for seqan3::tuple_like to test for std::get-interface.
Subconcept definition for seqan3::tuple_like to test for std::tuple_size-interface.
Whether a type behaves like a tuple with exactly two elements.
Whether a type behaves like a tuple.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
#define SEQAN3_RETURN_TYPE_CONSTRAINT(expression, concept_name,...)
Same as writing {expression} -> concept_name<type1[, ...]> in a concept definition.
Definition: platform.hpp:57
Helper type trait function to check for std::totally_ordered on all elements of the given tuple type.
Definition: concept.hpp:79
Transformation trait to expose the tuple element types as seqan3::type_list.
Definition: concept.hpp:95
static constexpr auto invoke_to_type_list(std::index_sequence< Is... >)
Helper function to extract the types using the tuple elements.
Definition: concept.hpp:100
decltype(invoke_to_type_list(std::make_index_sequence< std::tuple_size< tuple_t >::value >{})) type
The generated seqan3::type_list.
Definition: concept.hpp:107
Provides seqan3::pod_tuple.
Provides seqan3::type_list.
Provides various type traits on generic types.