ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMetaProgrammingLibrary.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
26 namespace mpl {
27 
38 struct TrueType
39 {
40  using ValueType = bool;
41  using Type = TrueType;
42 
43  static constexpr ValueType Value = true;
44  operator ValueType() { return Value; }
45 };
46 
51 struct FalseType
52 {
53  using ValueType = bool;
54  using Type = FalseType;
55  static constexpr ValueType Value = false;
56  operator ValueType() { return Value; }
57 };
58 
66 template <bool VP, typename T1, typename T2> struct If;
68 template <typename T1, typename T2> struct If<true , T1, T2>{ using Type = T1; };
69 template <typename T1, typename T2> struct If<false, T1, T2>{ using Type = T2; };
71 
79 template < bool VF1, bool VF2, bool VF3=false> struct OrC : TrueType { };
81 template <> struct OrC<false, false,false> : FalseType {};
83 
96 template < typename TF1, typename TF2, typename TF3=FalseType> struct Or : OrC<TF1::Value, TF2::Value, TF3::Value>
98 
105 template < bool VF1, bool VF2> struct AndC : FalseType { };
107 template <> struct AndC<true, true> : TrueType {};
109 
121 template < typename TF1, typename TF2> struct And : AndC<TF1::Value, TF2::Value>
123 
130 template < bool VF1, bool VF2> struct XorC : FalseType { };
132 template <> struct XorC<true, false> : TrueType {};
133 template <> struct XorC<false, true> : TrueType {};
135 
147 template < typename TF1, typename TF2> struct Xor : XorC<TF1::Value, TF2::Value>
149 
155 template < bool VF > struct NotC : FalseType { };
157 template <> struct NotC<false> : TrueType {};
158 template <> struct NotC<true> : FalseType {};
160 
171 template < typename TF> struct Not : NotC<TF::Value>
172 { using Type = typename NotC<TF::Value>::Type; };
173 
174 } // mpl namespace
175 
176 // TrueType and FalseType have moved to itk::mpl.
177 // Expect itk::TrueType and itk::False type to be deprecated.
178 using mpl::TrueType;
179 using mpl::FalseType;
180 
182 } // itk namespace
183 #endif // itkMetaProgrammingLibrary_h
typename XorC< TF1::Value, TF2::Value >::Type Type
typename OrC< TF1::Value, TF2::Value, TF3::Value >::Type Type
typename AndC< TF1::Value, TF2::Value >::Type Type
typename NotC< TF::Value >::Type Type