Permalink
Browse files

Merge branch 'master' of github.com:saleyn/utxx

  • Loading branch information...
saleyn committed Jul 17, 2014
2 parents a050208 + 789b547 commit 4d0d0d3df36e0b35523b4f00966d5881d721c940
Showing with 15 additions and 2 deletions.
  1. +15 −2 include/utxx/meta.hpp
View
@@ -53,15 +53,28 @@ struct pow {
template <size_t N> struct pow<N, 0> { static const size_t value = 1; };
template <size_t Power> struct pow<0, Power> { static const size_t value = 0; };
-/// Computes the power of \a base equal or greater than number \a n.
-template <size_t N, size_t Base = 2>
+/// Computes the smallest power of \a base equal or greater than number \a n.
+template <size_t N, size_t Base>
class upper_power {
static const size_t s_log = log<N,Base>::value;
static const size_t s_pow = pow<Base,s_log>::value;
public:
static const size_t value = s_pow == N ? N : s_pow*Base;
};
+// We need specialisation of "upper_power" for N=0, because the log cannot be
+// computed in that case (as required in the generic case above). The result
+// is 0 in this case (the corresp exponent of Base is "-oo") (XXX: even if
+// Base==0):
+template<size_t Base>
+class upper_power<0, Base> {
+public:
+ static const size_t value = 0;
+};
+
+template <size_t N>
+using upper_power2 = upper_power<N, 2>;
+
/// Given the size N and alignment size get the number of padding and aligned
/// space needed to hold the structure of N bytes.
template<int N, int Size>

0 comments on commit 4d0d0d3

Please sign in to comment.