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
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>
66 requires requires { typename instantiate<t>::type; }
67using instantiate_t = typename instantiate<t>::type;
68
69// ----------------------------------------------------------------------------
70// instantiate_if
71// ----------------------------------------------------------------------------
72
79template <typename t, bool condition>
80struct instantiate_if : std::false_type
81{};
82
89template <typename t>
90struct instantiate_if<t, true> : std::type_identity<t>
91{};
92
100template <template <typename...> typename template_t, typename... spec_t>
101struct instantiate_if<lazy<template_t, spec_t...>, true>
102{
104 using type = template_t<spec_t...>;
105};
106
111template <typename t, bool condition>
112 requires requires { typename instantiate_if<t, condition>::type; }
113using instantiate_if_t = typename instantiate_if<t, condition>::type;
114
119template <typename t, bool condition>
120 requires requires { instantiate_if_t<t, condition>::value; }
121inline constexpr auto instantiate_if_v = instantiate_if_t<t, condition>::value;
122
123// ----------------------------------------------------------------------------
124// lazy_conditional
125// ----------------------------------------------------------------------------
126
140template <bool decision, typename on_true_t, typename on_false_t>
141struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on_false_t>>
142{};
143
150template <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>>; }
152using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;
153
154} // namespace seqan3::detail
Provides platform and dependency checks.