SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
tuple.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 <tuple>
16 #include <type_traits>
17 
22 #include <seqan3/std/concepts>
23 
24 namespace seqan3::detail
25 {
26 
32 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 
45 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>
78 struct models_strict_totally_ordered
79 {
84 };
85 
93 template <detail::tuple_size tuple_t>
94 struct tuple_type_list
95 {
96 protected:
97 
99  template <size_t ... Is>
100  static constexpr auto invoke_to_type_list(std::index_sequence<Is...>)
101  {
102  return type_list<std::tuple_element_t<Is, tuple_t>...>{};
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>
116 using tuple_type_list_t = typename tuple_type_list<tuple_t>::type;
117 } // namespace::seqan3
118 
119 namespace seqan3
120 {
121 
122 // ----------------------------------------------------------------------------
123 // tuple_like
124 // ----------------------------------------------------------------------------
125 
173 template <typename t>
176 SEQAN3_CONCEPT tuple_like = detail::tuple_size<std::remove_reference_t<t>> && requires(t v)
177 {
178  typename detail::tuple_type_list<std::remove_cvref_t<t>>::type;
179 
180  // NOTE(rrahn): To check the full tuple_concept including the get interface and the std::totally_ordered
181  // we need to make some assumptions. In general these checks can only be executed if the tuple is not
182  // empty. Furthermore, the std::totally_ordered can only be checked if all elements in the
183  // tuple are strict_totally_ordered. This is done, by the fold expression in the second part.
184  requires (std::tuple_size<std::remove_reference_t<t>>::value == 0) ||
185  (detail::tuple_get<std::remove_cvref_t<t>> &&
186  (!meta::fold<detail::tuple_type_list_t<std::remove_cvref_t<t>>,
188  meta::quote_trait<detail::models_strict_totally_ordered>>::value ||
189  std::totally_ordered<std::remove_cvref_t<t>>));
190 };
192 
203 template <typename t>
205 SEQAN3_CONCEPT pair_like = tuple_like<t> && std::tuple_size_v<std::remove_reference_t<t>> == 2;
207 
208 } // namespace seqan3
std::true_type
pod_tuple.hpp
Provides seqan3::pod_tuple.
std::index_sequence
basic.hpp
Provides various type traits on generic types.
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
tuple
concepts
The Concepts library.
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SEQAN3_RETURN_TYPE_CONSTRAINT
#define SEQAN3_RETURN_TYPE_CONSTRAINT(expression, concept_name,...)
Same as writing {expression} -> concept_name<type1[, ...]> in a concept definition.
Definition: platform.hpp:57
tuple_like
Whether a type behaves like a tuple.
std::remove_reference_t
pair_like
Whether a type behaves like a tuple with exactly two elements.
std::conditional_t
type_list.hpp
Provides seqan3::type_list.