All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IsPowerOf.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_VALUETRAITS_ISPOWEROF_H_
23 #define _BLAZE_UTIL_VALUETRAITS_ISPOWEROF_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <blaze/util/FalseType.h>
31 #include <blaze/util/SelectType.h>
32 #include <blaze/util/TrueType.h>
33 
34 
35 namespace blaze {
36 
37 //=================================================================================================
38 //
39 // CLASS DEFINITION
40 //
41 //=================================================================================================
42 
43 //*************************************************************************************************
66 template< size_t B, size_t N >
67 struct IsPowerOf : public SelectType<N%B,FalseType,typename IsPowerOf<B,N/B>::Type>::Type
68 {
69  public:
70  //**********************************************************************************************
72  enum { value = ( N%B )?( 0 ):( IsPowerOf<B,N/B>::value ) };
73  typedef typename SelectType<N%B,FalseType,typename IsPowerOf<B,N/B>::Type>::Type Type;
75  //**********************************************************************************************
76 };
77 //*************************************************************************************************
78 
79 
80 //*************************************************************************************************
90 template< size_t N >
91 struct IsPowerOf<2,N> : public SelectType<N&(N-1),FalseType,TrueType>::Type
92 {
93  public:
94  //**********************************************************************************************
95  enum { value = ( N&(N-1) )?( 0 ):( 1 ) };
96  typedef typename SelectType<N&(N-1),FalseType,TrueType>::Type Type;
97  //**********************************************************************************************
98 };
100 //*************************************************************************************************
101 
102 
103 //*************************************************************************************************
112 template<>
113 struct IsPowerOf<2,0> : public FalseType
114 {
115  public:
116  //**********************************************************************************************
117  enum { value = 0 };
118  typedef FalseType Type;
119  //**********************************************************************************************
120 };
122 //*************************************************************************************************
123 
124 
125 //*************************************************************************************************
135 template< size_t B >
136 struct IsPowerOf<B,1> : public TrueType
137 {
138  public:
139  //**********************************************************************************************
140  enum { value = 1 };
141  typedef TrueType Type;
142  //**********************************************************************************************
143 };
145 //*************************************************************************************************
146 
147 
148 //*************************************************************************************************
158 template< size_t N >
159 struct IsPowerOf<1,N> : public FalseType
160 {
161  public:
162  //**********************************************************************************************
163  enum { value = 0 };
164  typedef FalseType Type;
165  //**********************************************************************************************
166 };
168 //*************************************************************************************************
169 
170 
171 //*************************************************************************************************
181 template<>
182 struct IsPowerOf<1,1> : public TrueType
183 {
184  public:
185  //**********************************************************************************************
186  enum { value = 1 };
187  typedef TrueType Type;
188  //**********************************************************************************************
189 };
191 //*************************************************************************************************
192 
193 
194 //*************************************************************************************************
204 template< size_t B >
205 struct IsPowerOf<B,0> : public FalseType
206 {
207  public:
208  //**********************************************************************************************
209  enum { value = 0 };
210  typedef FalseType Type;
211  //**********************************************************************************************
212 };
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
227 template< size_t N >
228 struct IsPowerOf<0,N> : public FalseType
229 {
230  public:
231  //**********************************************************************************************
232  enum { value = 0 };
233  typedef FalseType Type;
234  //**********************************************************************************************
235 };
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
250 template<>
251 struct IsPowerOf<0,0> : public TrueType
252 {
253  public:
254  //**********************************************************************************************
255  enum { value = 1 };
256  typedef TrueType Type;
257  //**********************************************************************************************
258 };
260 //*************************************************************************************************
261 
262 } // namespace blaze
263 
264 #endif