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 : public BoolConstant< IsPowerOf<B,N/B>::value >
81 {};
82 //*************************************************************************************************
83 
84 
85 //*************************************************************************************************
95 template< size_t N >
96 struct IsPowerOf<2,N> : public BoolConstant< ( N & (N-1) ) == 0UL >
97 {};
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
111 template<>
112 struct IsPowerOf<2,0> : public FalseType
113 {};
115 //*************************************************************************************************
116 
117 
118 //*************************************************************************************************
128 template< size_t B >
129 struct IsPowerOf<B,1> : public TrueType
130 {};
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
145 template< size_t N >
146 struct IsPowerOf<1,N> : public FalseType
147 {};
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
162 template<>
163 struct IsPowerOf<1,1> : public TrueType
164 {};
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
179 template< size_t B >
180 struct IsPowerOf<B,0> : public FalseType
181 {};
183 //*************************************************************************************************
184 
185 
186 //*************************************************************************************************
196 template< size_t N >
197 struct IsPowerOf<0,N> : public FalseType
198 {};
200 //*************************************************************************************************
201 
202 
203 //*************************************************************************************************
213 template<>
214 struct IsPowerOf<0,0> : public TrueType
215 {};
217 //*************************************************************************************************
218 
219 } // namespace blaze
220 
221 #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
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:57
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.