SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
lazy.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 
19 #include <seqan3/std/type_traits>
20 
21 namespace seqan3::detail
22 {
23 
28 // ----------------------------------------------------------------------------
29 // lazy
30 // ----------------------------------------------------------------------------
31 
36 template <template <typename ...> typename template_t, typename ...spec_t>
37 struct lazy
38 {};
39 
40 // ----------------------------------------------------------------------------
41 // instantiate
42 // ----------------------------------------------------------------------------
43 
48 template <typename t>
49 struct instantiate : std::type_identity<t>
50 {};
51 
57 template <template <typename ...> typename template_t, typename ...spec_t>
58 struct instantiate<lazy<template_t, spec_t...>>
59 {
61  using type = template_t<spec_t...>;
62 };
63 
68 template <typename t>
70  requires requires { typename instantiate<t>::type; }
72 using instantiate_t = typename instantiate<t>::type;
73 
74 // ----------------------------------------------------------------------------
75 // instantiate_if
76 // ----------------------------------------------------------------------------
77 
83 template <typename t, bool condition>
84 struct instantiate_if : std::false_type
85 {};
86 
92 template <typename t>
93 struct instantiate_if<t, true> : std::type_identity<t>
94 {};
95 
102 template <template <typename ...> typename template_t, typename ...spec_t>
103 struct instantiate_if<lazy<template_t, spec_t...>, true>
104 {
106  using type = template_t<spec_t...>;
107 };
108 
113 template <typename t, bool condition>
115  requires requires { typename instantiate_if<t, condition>::type; }
117 using instantiate_if_t = typename instantiate_if<t, condition>::type;
118 
123 template <typename t, bool condition>
125  requires requires { instantiate_if_t<t, condition>::value; }
127 inline constexpr auto instantiate_if_v = instantiate_if_t<t, condition>::value;
128 
129 // ----------------------------------------------------------------------------
130 // lazy_conditional
131 // ----------------------------------------------------------------------------
132 
145 template <bool decision, typename on_true_t, typename on_false_t>
146 struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on_false_t>>
147 {};
148 
155 template <bool decision, typename on_true_t, typename on_false_t>
157  requires requires { typename instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>; }
159 using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;
160 
179 template <template <typename ...> typename query_t, typename ...args_t>
180 struct is_class_template_declarable_with :
182  public std::false_type
184 {};
185 
187 template <template <typename ...> typename query_t, typename ...args_t>
188  requires requires { typename std::type_identity<query_t<args_t...>>::type; }
189 struct is_class_template_declarable_with<query_t, args_t...> : public std::true_type
190 {};
192 
198 template <template <typename ...> typename query_t, typename ...args_t>
199 inline constexpr bool is_class_template_declarable_with_v = is_class_template_declarable_with<query_t, args_t...>::value;
201 } // namespace seqan3::detail
function.hpp
Provides various type traits for use on functions.
std::false_type
type_traits
Provides C++20 additions to the type_traits header.
tuple
std::type_identity
The identity transformation (a transformation_trait that returns the input).
Definition: type_traits:31