SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
concept.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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
24namespace seqan3::detail
25{
26
33template <typename tuple_t>
34concept tuple_size = requires (tuple_t v)
35{
36 {std::tuple_size<tuple_t>::value} -> std::convertible_to<size_t>;
37};
39
46template <typename tuple_t>
47concept 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 {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 {get<0>(v_c)} -> std::convertible_to<typename std::tuple_element<0, tuple_t>::type>;
59 {get<0>(std::move(v))} -> std::convertible_to<typename std::tuple_element<0, tuple_t>::type>;
60 {get<0>(std::move(v_c))} -> std::convertible_to<typename std::tuple_element<0, tuple_t>::type const &&>;
61};
63
71template <detail::tuple_size tuple_t>
73{
74protected:
75
77 template <size_t ... Is>
79 {
81 }
82
83public:
85 using type = decltype(invoke_to_type_list(std::make_index_sequence<std::tuple_size<tuple_t>::value>{}));
86};
87
93template <detail::tuple_size tuple_t>
95
99template <typename ...elements_t>
101 -> std::bool_constant<(std::totally_ordered<elements_t> && ... && true)>;
102
107template <typename tuple_t>
109 requires requires()
110 {
112 }
114static constexpr bool all_elements_model_totally_ordered_v =
115 decltype(detail::all_elements_model_totally_ordered(tuple_type_list_t<tuple_t>{}))::value;
116} // namespace seqan3::detail
117
118namespace seqan3
119{
120
121// ----------------------------------------------------------------------------
122// tuple_like
123// ----------------------------------------------------------------------------
124
174template <typename t>
175concept tuple_like = detail::tuple_size<std::remove_reference_t<t>> && requires(t v)
176{
177 typename detail::tuple_type_list<std::remove_cvref_t<t>>::type;
178
179 // NOTE(rrahn): To check the full tuple_concept including the get interface and the std::totally_ordered
180 // we need to make some assumptions. In general these checks can only be executed if the tuple is not
181 // empty. Furthermore, the std::totally_ordered can only be checked if all elements in the
182 // tuple are strict_totally_ordered. This is done, by the fold expression in the second part.
183 requires (std::tuple_size<std::remove_reference_t<t>>::value == 0) ||
184 (detail::tuple_get<std::remove_cvref_t<t>> &&
185 (!detail::all_elements_model_totally_ordered_v<std::remove_cvref_t<t>> ||
186 std::totally_ordered<std::remove_cvref_t<t>>));
187};
189
201template <typename t>
202concept pair_like = tuple_like<t> && std::tuple_size_v<std::remove_reference_t<t>> == 2;
204
205} // namespace seqan3
Provides various type traits on generic types.
The <concepts> header from C++20's standard library.
typename tuple_type_list< tuple_t >::type tuple_type_list_t
Helper type for seqan3::detail::tuple_type_list.
Definition: concept.hpp:94
constexpr auto all_elements_model_totally_ordered(seqan3::type_list< elements_t... >) -> std::bool_constant<(std::totally_ordered< elements_t > &&... &&true)>
Helper type function to check for std::totally_ordered on all elements of the given tuple type.
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
Provides seqan3::pod_tuple.
Transformation trait to expose the tuple element types as seqan3::type_list.
Definition: concept.hpp:73
static constexpr auto invoke_to_type_list(std::index_sequence< Is... >)
Helper function to extract the types using the tuple elements.
Definition: concept.hpp:78
decltype(invoke_to_type_list(std::make_index_sequence< std::tuple_size< tuple_t >::value >{})) type
The generated seqan3::type_list.
Definition: concept.hpp:85
Type that contains multiple types.
Definition: type_list.hpp:29
Provides type traits for working with templates.
Provides seqan3::type_list.