SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
lazy_conditional.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 <type_traits>
16 
17 #include <seqan3/core/platform.hpp>
18 
19 namespace seqan3::detail
20 {
21 
22 // ----------------------------------------------------------------------------
23 // lazy
24 // ----------------------------------------------------------------------------
25 
31 template <template <typename...> typename template_t, typename... spec_t>
32 struct lazy
33 {};
34 
35 // ----------------------------------------------------------------------------
36 // instantiate
37 // ----------------------------------------------------------------------------
38 
44 template <typename t>
45 struct instantiate : std::type_identity<t>
46 {};
47 
54 template <template <typename...> typename template_t, typename... spec_t>
55 struct instantiate<lazy<template_t, spec_t...>>
56 {
58  using type = template_t<spec_t...>;
59 };
60 
65 template <typename t>
66  requires requires { typename instantiate<t>::type; }
67 using instantiate_t = typename instantiate<t>::type;
68 
69 // ----------------------------------------------------------------------------
70 // instantiate_if
71 // ----------------------------------------------------------------------------
72 
79 template <typename t, bool condition>
80 struct instantiate_if : std::false_type
81 {};
82 
89 template <typename t>
90 struct instantiate_if<t, true> : std::type_identity<t>
91 {};
92 
100 template <template <typename...> typename template_t, typename... spec_t>
101 struct instantiate_if<lazy<template_t, spec_t...>, true>
102 {
104  using type = template_t<spec_t...>;
105 };
106 
111 template <typename t, bool condition>
112  requires requires { typename instantiate_if<t, condition>::type; }
113 using instantiate_if_t = typename instantiate_if<t, condition>::type;
114 
119 template <typename t, bool condition>
120  requires requires { instantiate_if_t<t, condition>::value; }
121 inline constexpr auto instantiate_if_v = instantiate_if_t<t, condition>::value;
122 
123 // ----------------------------------------------------------------------------
124 // lazy_conditional
125 // ----------------------------------------------------------------------------
126 
140 template <bool decision, typename on_true_t, typename on_false_t>
141 struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on_false_t>>
142 {};
143 
150 template <bool decision, typename on_true_t, typename on_false_t>
151  requires requires { typename instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>; }
152 using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;
153 
154 } // namespace seqan3::detail
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
Provides platform and dependency checks.