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 
24 namespace itk
25 {
26 
28 namespace mpl
29 {
30 
41 struct TrueType
42 {
43  using ValueType = bool;
44  using Type = TrueType;
45 
46  static constexpr ValueType Value = true;
47  operator ValueType() { return Value; }
48 };
49 
54 struct FalseType
55 {
56  using ValueType = bool;
57  using Type = FalseType;
58  static constexpr ValueType Value = false;
59  operator ValueType() { return Value; }
60 };
61 
69 template <bool VP, typename T1, typename T2>
70 struct If;
72 template <typename T1, typename T2>
73 struct If<true, T1, T2>
74 {
75  using Type = T1;
76 };
77 template <typename T1, typename T2>
78 struct If<false, T1, T2>
79 {
80  using Type = T2;
81 };
83 
91 template <bool VF1, bool VF2, bool VF3 = false>
92 struct OrC : TrueType
93 {};
95 template <>
96 struct OrC<false, false, false> : FalseType
97 {};
99 
112 template <typename TF1, typename TF2, typename TF3 = FalseType>
113 struct Or : OrC<TF1::Value, TF2::Value, TF3::Value>
114 {
116 };
117 
124 template <bool VF1, bool VF2>
125 struct AndC : FalseType
126 {};
128 template <>
129 struct AndC<true, true> : TrueType
130 {};
132 
144 template <typename TF1, typename TF2>
145 struct And : AndC<TF1::Value, TF2::Value>
146 {
148 };
149 
156 template <bool VF1, bool VF2>
157 struct XorC : FalseType
158 {};
160 template <>
161 struct XorC<true, false> : TrueType
162 {};
163 template <>
164 struct XorC<false, true> : TrueType
165 {};
167 
179 template <typename TF1, typename TF2>
180 struct Xor : XorC<TF1::Value, TF2::Value>
181 {
183 };
184 
190 template <bool VF>
191 struct NotC : FalseType
192 {};
194 template <>
195 struct NotC<false> : TrueType
196 {};
197 template <>
198 struct NotC<true> : FalseType
199 {};
201 
212 template <typename TF>
213 struct Not : NotC<TF::Value>
214 {
215  using Type = typename NotC<TF::Value>::Type;
216 };
217 
220 template <typename T>
221 struct IsSmartPointer : FalseType
222 {};
223 
224 
226 template <typename T>
227 struct IsSmartPointer<SmartPointer<T>> : TrueType
228 {};
229 
230 template <typename T>
231 struct IsSmartPointer<const SmartPointer<T>> : TrueType
232 {};
234 
240 template <typename TFromType, typename TToType>
241 using 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.
249 using mpl::TrueType;
250 using mpl::FalseType;
251 
253 } // namespace itk
254 #endif // itkMetaProgrammingLibrary_h
itk::XorC
Definition: itkMetaProgrammingLibrary.h:157
itk::And
Definition: itkMetaProgrammingLibrary.h:145
itk::NotC
Definition: itkMetaProgrammingLibrary.h:191
itk::Xor::Type
typename XorC< TF1::Value, TF2::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:182
itk::AndC
Definition: itkMetaProgrammingLibrary.h:125
itk::SmartPointer
Implements transparent reference counting.
Definition: itkSmartPointer.h:51
itk::And::Type
typename AndC< TF1::Value, TF2::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:147
itk::OrC
Definition: itkMetaProgrammingLibrary.h:92
itkMacro.h
itk::is_static_castable
std::integral_constant< bool, std::is_constructible_v< TToType, TFromType >||std::is_convertible_v< TFromType, TToType > > is_static_castable
Definition: itkMetaProgrammingLibrary.h:243
itk::Not::Type
typename NotC< TF::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:215
itk::Or
Definition: itkMetaProgrammingLibrary.h:113
itk::Not
Definition: itkMetaProgrammingLibrary.h:213
itk::Or::Type
typename OrC< TF1::Value, TF2::Value, TF3::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:115
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::IsSmartPointer
Definition: itkMetaProgrammingLibrary.h:221
itkSmartPointer.h
itk::Xor
Definition: itkMetaProgrammingLibrary.h:180