ITK  5.1.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  * http://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 
23 namespace itk
24 {
25 
27 namespace mpl
28 {
29 
40 struct TrueType
41 {
42  using ValueType = bool;
43  using Type = TrueType;
44 
45  static constexpr ValueType Value = true;
46  operator ValueType() { return Value; }
47 };
48 
53 struct FalseType
54 {
55  using ValueType = bool;
56  using Type = FalseType;
57  static constexpr ValueType Value = false;
58  operator ValueType() { return Value; }
59 };
60 
68 template <bool VP, typename T1, typename T2>
69 struct If;
71 template <typename T1, typename T2>
72 struct If<true, T1, T2>
73 {
74  using Type = T1;
75 };
76 template <typename T1, typename T2>
77 struct If<false, T1, T2>
78 {
79  using Type = T2;
80 };
82 
90 template <bool VF1, bool VF2, bool VF3 = false>
91 struct OrC : TrueType
92 {};
94 template <>
95 struct OrC<false, false, false> : FalseType
96 {};
98 
111 template <typename TF1, typename TF2, typename TF3 = FalseType>
112 struct Or : OrC<TF1::Value, TF2::Value, TF3::Value>
113 {
115 };
116 
123 template <bool VF1, bool VF2>
124 struct AndC : FalseType
125 {};
127 template <>
128 struct AndC<true, true> : TrueType
129 {};
131 
143 template <typename TF1, typename TF2>
144 struct And : AndC<TF1::Value, TF2::Value>
145 {
147 };
148 
155 template <bool VF1, bool VF2>
156 struct XorC : FalseType
157 {};
159 template <>
160 struct XorC<true, false> : TrueType
161 {};
162 template <>
163 struct XorC<false, true> : TrueType
164 {};
166 
178 template <typename TF1, typename TF2>
179 struct Xor : XorC<TF1::Value, TF2::Value>
180 {
182 };
183 
189 template <bool VF>
190 struct NotC : FalseType
191 {};
193 template <>
194 struct NotC<false> : TrueType
195 {};
196 template <>
197 struct NotC<true> : FalseType
198 {};
200 
211 template <typename TF>
212 struct Not : NotC<TF::Value>
213 {
214  using Type = typename NotC<TF::Value>::Type;
215 };
216 
222 template <typename TFromType, typename TToType>
223 using is_static_castable = std::integral_constant<bool,
224  std::is_constructible<TToType, TFromType>::value ||
225  std::is_convertible<TFromType, TToType>::value>;
226 } // namespace mpl
227 
228 
229 // TrueType and FalseType have moved to itk::mpl.
230 // Expect itk::TrueType and itk::False type to be deprecated.
231 using mpl::TrueType;
232 using mpl::FalseType;
233 
235 } // namespace itk
236 #endif // itkMetaProgrammingLibrary_h
itk::XorC
Definition: itkMetaProgrammingLibrary.h:156
itk::And
Definition: itkMetaProgrammingLibrary.h:144
itk::NotC
Definition: itkMetaProgrammingLibrary.h:190
itk::Xor::Type
typename XorC< TF1::Value, TF2::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:181
itk::AndC
Definition: itkMetaProgrammingLibrary.h:124
itk::And::Type
typename AndC< TF1::Value, TF2::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:146
itk::OrC
Definition: itkMetaProgrammingLibrary.h:91
itkMacro.h
itk::Not::Type
typename NotC< TF::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:214
itk::Or
Definition: itkMetaProgrammingLibrary.h:112
itk::Not
Definition: itkMetaProgrammingLibrary.h:212
itk::Or::Type
typename OrC< TF1::Value, TF2::Value, TF3::Value >::Type Type
Definition: itkMetaProgrammingLibrary.h:114
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::is_static_castable
std::integral_constant< bool, std::is_constructible< TToType, TFromType >::value||std::is_convertible< TFromType, TToType >::value > is_static_castable
Definition: itkMetaProgrammingLibrary.h:225
itk::Xor
Definition: itkMetaProgrammingLibrary.h:179