IsPowerOf.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_VALUETRAITS_ISPOWEROF_H_
36 #define _BLAZE_UTIL_VALUETRAITS_ISPOWEROF_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/FalseType.h>
45 #include <blaze/util/TrueType.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
79 template< size_t B, size_t N >
80 struct IsPowerOf
81  : public BoolConstant< IsPowerOf<B,N/B>::value >
82 {};
83 //*************************************************************************************************
84 
85 
86 //*************************************************************************************************
96 template< size_t N >
97 struct IsPowerOf<2,N>
98  : public BoolConstant< ( N & (N-1) ) == 0UL >
99 {};
101 //*************************************************************************************************
102 
103 
104 //*************************************************************************************************
113 template<>
114 struct IsPowerOf<2,0>
115  : public FalseType
116 {};
118 //*************************************************************************************************
119 
120 
121 //*************************************************************************************************
131 template< size_t B >
132 struct IsPowerOf<B,1>
133  : public TrueType
134 {};
136 //*************************************************************************************************
137 
138 
139 //*************************************************************************************************
149 template< size_t N >
150 struct IsPowerOf<1,N>
151  : public FalseType
152 {};
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
167 template<>
168 struct IsPowerOf<1,1>
169  : public TrueType
170 {};
172 //*************************************************************************************************
173 
174 
175 //*************************************************************************************************
185 template< size_t B >
186 struct IsPowerOf<B,0>
187  : public FalseType
188 {};
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
203 template< size_t N >
204 struct IsPowerOf<0,N>
205  : public FalseType
206 {};
208 //*************************************************************************************************
209 
210 
211 //*************************************************************************************************
221 template<>
222 struct IsPowerOf<0,0>
223  : public TrueType
224 {};
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
242 template< size_t B, size_t N >
244 //*************************************************************************************************
245 
246 } // namespace blaze
247 
248 #endif
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
Header file for the FalseType type/value trait base class.
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
constexpr bool IsPowerOf_v
Auxiliary variable template for the IsPowerOf value trait.The IsPowerOf_v variable template provides ...
Definition: IsPowerOf.h:243
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the IntegralConstant class template.
Compile time check for a power relationship of integral values to a given base.This value trait tests...
Definition: IsPowerOf.h:80
Header file for the TrueType type/value trait base class.