SeqAn3 3.1.0
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
16
18
19namespace seqan3::detail
20{
21
22// ----------------------------------------------------------------------------
23// lazy
24// ----------------------------------------------------------------------------
25
31template <template <typename ...> typename template_t, typename ...spec_t>
32struct lazy
33{};
34
35// ----------------------------------------------------------------------------
36// instantiate
37// ----------------------------------------------------------------------------
38
44template <typename t>
45struct instantiate : std::type_identity<t>
46{};
47
54template <template <typename ...> typename template_t, typename ...spec_t>
55struct instantiate<lazy<template_t, spec_t...>>
56{
58 using type = template_t<spec_t...>;
59};
60
65template <typename t>
67 requires requires { typename instantiate<t>::type; }
69using instantiate_t = typename instantiate<t>::type;
70
71// ----------------------------------------------------------------------------
72// instantiate_if
73// ----------------------------------------------------------------------------
74
81template <typename t, bool condition>
82struct instantiate_if : std::false_type
83{};
84
91template <typename t>
92struct instantiate_if<t, true> : std::type_identity<t>
93{};
94
102template <template <typename ...> typename template_t, typename ...spec_t>
103struct instantiate_if<lazy<template_t, spec_t...>, true>
104{
106 using type = template_t<spec_t...>;
107};
108
113template <typename t, bool condition>
115 requires requires { typename instantiate_if<t, condition>::type; }
117using instantiate_if_t = typename instantiate_if<t, condition>::type;
118
123template <typename t, bool condition>
125 requires requires { instantiate_if_t<t, condition>::value; }
127inline constexpr auto instantiate_if_v = instantiate_if_t<t, condition>::value;
128
129// ----------------------------------------------------------------------------
130// lazy_conditional
131// ----------------------------------------------------------------------------
132
146template <bool decision, typename on_true_t, typename on_false_t>
147struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on_false_t>>
148{};
149
156template <bool decision, typename on_true_t, typename on_false_t>
158 requires requires { typename instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>; }
160using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;
161
162} // namespace seqan3::detail
Provides platform and dependency checks.
The <type_traits> header from C++20's standard library.