fennec
Loading...
Searching...
No Matches
conditional_types.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31
32#ifndef FENNEC_LANG_CONDITIONAL_TYPES_H
33#define FENNEC_LANG_CONDITIONAL_TYPES_H
34
35#include <fennec/lang/type_identity.h>
36
68
69namespace fennec
70{
71
72// fennec::conditional =================================================================================================
73
82template<bool B, typename TrueT, typename FalseT>
84
85
88template<bool B, typename TrueT, typename FalseT>
91
92
93// specialization of fennec::conditional for `true` case
94template<typename T, typename F>
95struct conditional<true, T, F> : type_identity<T>{};
96
97
98// specialization of fennec::conditional for `false` case
99template<typename T, typename F>
100struct conditional<false, T, F> : type_identity<F>{};
101
102
103// fennec::detect ======================================================================================================
104
113template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
114struct detect
115{
116 using type = DefaultT;
117 static constexpr bool is_detected = false;
118};
119
122template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
123using detect_t = typename detect<DefaultT, DetectT, ArgsT...>::type;
124
125
126// true case
127template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
128 requires requires { typename DetectT<ArgsT...>; }
129struct detect<DefaultT, DetectT, ArgsT...>
130{
131 using type = DetectT<ArgsT...>;
132 static constexpr bool is_detected = true;
133};
134
135
136// fennec::enable_if ===================================================================================================
137
151template<bool B, typename T = void>
152struct enable_if {};
153
156template<bool B, typename T = void>
158
159// true case
160template<typename T>
161struct enable_if<true, T> { using type = T; };
162
163}
164
165#endif // FENNEC_LANG_CONDITIONAL_TYPES_H
typename enable_if< B, T >::type enable_if_t
Shorthand for typename enable_if<B, T>::type
Definition conditional_types.h:157
typename detect< DefaultT, DetectT, ArgsT... >::type detect_t
Shorthand for typename detect<DefaultT, DetectT, ArgsT...>::type
Definition conditional_types.h:123
typename conditional< B, TrueT, FalseT >::type conditional_t
Shorthand for typename conditional<ConditionV, TrueT, FalseT>::type
Definition conditional_types.h:90
select between two types based on a condition
Definition conditional_types.h:83
Detect whether DetectT<ArgsT...> is a valid type.
Definition conditional_types.h:115
Leverage SFINAE to conditionally enable a function or class at compile-time.
Definition conditional_types.h:152
Base Class for Type Transformations.
Definition type_identity.h:49