ITK  6.0.0
Insight Toolkit
itkMetaProgrammingLibrary.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkMetaProgrammingLibrary_h
19#define itkMetaProgrammingLibrary_h
20
21#include "itkMacro.h"
22#include "itkSmartPointer.h"
23
24namespace itk
25{
26
28namespace mpl
29{
30
41struct TrueType
42{
43 using ValueType = bool;
44 using Type = TrueType;
45
46 static constexpr ValueType Value = true;
47 operator ValueType() { return Value; }
48};
49
54struct FalseType
55{
56 using ValueType = bool;
57 using Type = FalseType;
58 static constexpr ValueType Value = false;
59 operator ValueType() { return Value; }
60};
61
69template <bool VP, typename T1, typename T2>
70struct If;
72template <typename T1, typename T2>
73struct If<true, T1, T2>
74{
75 using Type = T1;
76};
77template <typename T1, typename T2>
78struct If<false, T1, T2>
79{
80 using Type = T2;
81};
83
91template <bool VF1, bool VF2, bool VF3 = false>
92struct OrC : TrueType
93{};
95template <>
96struct OrC<false, false, false> : FalseType
97{};
99
112template <typename TF1, typename TF2, typename TF3 = FalseType>
113struct Or : OrC<TF1::Value, TF2::Value, TF3::Value>
114{
115 using Type = typename OrC<TF1::Value, TF2::Value, TF3::Value>::Type;
116};
117
124template <bool VF1, bool VF2>
125struct AndC : FalseType
126{};
128template <>
129struct AndC<true, true> : TrueType
130{};
132
144template <typename TF1, typename TF2>
145struct And : AndC<TF1::Value, TF2::Value>
146{
147 using Type = typename AndC<TF1::Value, TF2::Value>::Type;
148};
149
156template <bool VF1, bool VF2>
157struct XorC : FalseType
158{};
160template <>
161struct XorC<true, false> : TrueType
162{};
163template <>
164struct XorC<false, true> : TrueType
165{};
167
179template <typename TF1, typename TF2>
180struct Xor : XorC<TF1::Value, TF2::Value>
181{
182 using Type = typename XorC<TF1::Value, TF2::Value>::Type;
183};
184
190template <bool VF>
191struct NotC : FalseType
192{};
194template <>
195struct NotC<false> : TrueType
196{};
197template <>
198struct NotC<true> : FalseType
199{};
201
212template <typename TF>
213struct Not : NotC<TF::Value>
214{
215 using Type = typename NotC<TF::Value>::Type;
216};
217
220template <typename T>
221struct IsSmartPointer : FalseType
222{};
223
224
226template <typename T>
227struct IsSmartPointer<SmartPointer<T>> : TrueType
228{};
229
230template <typename T>
231struct IsSmartPointer<const SmartPointer<T>> : TrueType
232{};
234
240template <typename TFromType, typename TToType>
241using is_static_castable =
242 std::integral_constant<bool,
243 std::is_constructible_v<TToType, TFromType> || std::is_convertible_v<TFromType, TToType>>;
244} // namespace mpl
245
246
247// TrueType and FalseType have moved to itk::mpl.
248// Expect itk::TrueType and itk::False type to be deprecated.
249using mpl::TrueType;
250using mpl::FalseType;
251
253} // namespace itk
254#endif // itkMetaProgrammingLibrary_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....