Blaze  3.6
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 
44 
45 
46 namespace blaze {
47 
48 //=================================================================================================
49 //
50 // CLASS DEFINITION
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
77 template< size_t B, size_t N >
78 struct IsPowerOf
79  : public BoolConstant< IsPowerOf<B,N/B>::value >
80 {};
81 //*************************************************************************************************
82 
83 
84 //*************************************************************************************************
94 template< size_t N >
95 struct IsPowerOf<2,N>
96  : public BoolConstant< ( N & (N-1) ) == 0UL >
97 {};
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
111 template<>
112 struct IsPowerOf<2,0>
113  : public FalseType
114 {};
116 //*************************************************************************************************
117 
118 
119 //*************************************************************************************************
129 template< size_t B >
130 struct IsPowerOf<B,1>
131  : public TrueType
132 {};
134 //*************************************************************************************************
135 
136 
137 //*************************************************************************************************
147 template< size_t N >
148 struct IsPowerOf<1,N>
149  : public FalseType
150 {};
152 //*************************************************************************************************
153 
154 
155 //*************************************************************************************************
165 template<>
166 struct IsPowerOf<1,1>
167  : public TrueType
168 {};
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
183 template< size_t B >
184 struct IsPowerOf<B,0>
185  : public FalseType
186 {};
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
201 template< size_t N >
202 struct IsPowerOf<0,N>
203  : public FalseType
204 {};
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
219 template<>
220 struct IsPowerOf<0,0>
221  : public TrueType
222 {};
224 //*************************************************************************************************
225 
226 
227 //*************************************************************************************************
240 template< size_t B, size_t N >
242 //*************************************************************************************************
243 
244 } // namespace blaze
245 
246 #endif
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: IntegralConstant.h:121
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:72
constexpr bool IsPowerOf_v
Auxiliary variable template for the IsPowerOf value trait.The IsPowerOf_v variable template provides ...
Definition: IsPowerOf.h:241
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
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:78