SeqAn3  3.0.3
The Modern C++ library for sequence analysis.
lazy_conditional.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/type_traits>
16 
17 #include <seqan3/core/platform.hpp>
18 
19 namespace seqan3::detail
20 {
21 
26 // ----------------------------------------------------------------------------
27 // lazy
28 // ----------------------------------------------------------------------------
29 
34 template <template <typename ...> typename template_t, typename ...spec_t>
35 struct lazy
36 {};
37 
38 // ----------------------------------------------------------------------------
39 // instantiate
40 // ----------------------------------------------------------------------------
41 
46 template <typename t>
47 struct instantiate : std::type_identity<t>
48 {};
49 
55 template <template <typename ...> typename template_t, typename ...spec_t>
56 struct instantiate<lazy<template_t, spec_t...>>
57 {
59  using type = template_t<spec_t...>;
60 };
61 
66 template <typename t>
68  requires requires { typename instantiate<t>::type; }
70 using instantiate_t = typename instantiate<t>::type;
71 
72 // ----------------------------------------------------------------------------
73 // instantiate_if
74 // ----------------------------------------------------------------------------
75 
81 template <typename t, bool condition>
82 struct instantiate_if : std::false_type
83 {};
84 
90 template <typename t>
91 struct instantiate_if<t, true> : std::type_identity<t>
92 {};
93 
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>
113  requires requires { typename instantiate_if<t, condition>::type; }
115 using instantiate_if_t = typename instantiate_if<t, condition>::type;
116 
121 template <typename t, bool condition>
123  requires requires { instantiate_if_t<t, condition>::value; }
125 inline constexpr auto instantiate_if_v = instantiate_if_t<t, condition>::value;
126 
127 // ----------------------------------------------------------------------------
128 // lazy_conditional
129 // ----------------------------------------------------------------------------
130 
143 template <bool decision, typename on_true_t, typename on_false_t>
144 struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on_false_t>>
145 {};
146 
153 template <bool decision, typename on_true_t, typename on_false_t>
155  requires requires { typename instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>; }
157 using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;
158 
160 
161 } // namespace seqan3::detail
Provides platform and dependency checks.
Provides C++20 additions to the type_traits header.