ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
36
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
111template <typename TF1, typename TF2, typename TF3 = FalseType>
112struct Or : OrC<TF1::Value, TF2::Value, TF3::Value>
113{
114 using Type = typename OrC<TF1::Value, TF2::Value, TF3::Value>::Type;
115};
116
123template <bool VF1, bool VF2>
124struct AndC : FalseType
125{};
127template <>
128struct AndC<true, true> : TrueType
129{};
131
142template <typename TF1, typename TF2>
143struct And : AndC<TF1::Value, TF2::Value>
144{
145 using Type = typename AndC<TF1::Value, TF2::Value>::Type;
146};
147
154template <bool VF1, bool VF2>
155struct XorC : FalseType
156{};
158template <>
159struct XorC<true, false> : TrueType
160{};
161template <>
162struct XorC<false, true> : TrueType
163{};
165
176template <typename TF1, typename TF2>
177struct Xor : XorC<TF1::Value, TF2::Value>
178{
179 using Type = typename XorC<TF1::Value, TF2::Value>::Type;
180};
181
187template <bool VF>
188struct NotC : FalseType
189{};
191template <>
192struct NotC<false> : TrueType
193{};
194template <>
195struct NotC<true> : FalseType
196{};
198
208template <typename TF>
209struct Not : NotC<TF::Value>
210{
211 using Type = typename NotC<TF::Value>::Type;
212};
213
216template <typename T>
217struct IsSmartPointer : FalseType
218{};
219
220
222template <typename T>
223struct IsSmartPointer<SmartPointer<T>> : TrueType
224{};
225
226template <typename T>
227struct IsSmartPointer<const SmartPointer<T>> : TrueType
228{};
230
236template <typename TFromType, typename TToType>
237using is_static_castable =
238 std::integral_constant<bool,
239 std::is_constructible_v<TToType, TFromType> || std::is_convertible_v<TFromType, TToType>>;
240} // namespace mpl
241
242
243// TrueType and FalseType have moved to itk::mpl.
244// Expect itk::TrueType and itk::False type to be deprecated.
245using mpl::TrueType;
246using mpl::FalseType;
247
249} // namespace itk
250#endif // itkMetaProgrammingLibrary_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....