|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63781 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-07-09 13:51:16
Author: murilov
Date: 2010-07-09 13:51:15 EDT (Fri, 09 Jul 2010)
New Revision: 63781
URL: http://svn.boost.org/trac/boost/changeset/63781
Log:
Added static_count_trailing_zeros<> and mpl::count_trailing_zeros<> static metafunctions and its test
Added:
sandbox/SOC/2010/bits_and_ints/boost/integer/static_count_trailing_zeros.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp 2010-07-09 13:51:15 EDT (Fri, 09 Jul 2010)
@@ -31,7 +31,7 @@
{
return pop_count(~value & (value - 1));
} // count_trailing_zeros
-
+
} // boost
#endif
Added: sandbox/SOC/2010/bits_and_ints/boost/integer/static_count_trailing_zeros.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_count_trailing_zeros.hpp 2010-07-09 13:51:15 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,56 @@
+// Boost integer/static_count_trailing_zeros.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_STATIC_COUNT_TRAILING_ZEROS_INCLUDED
+#define BOOST_STATIC_COUNT_TRAILING_ZEROS_INCLUDED
+
+#include <boost/cstdint.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/integer/static_pop_count.hpp>
+#include <boost/integer/is_integral_constant.hpp>
+
+/*
+ * static_count_trailing_zeros and mpl::count_trailing_zeros
+ * counts the number of consecutive 0's
+ * from the least significant bit of integral constants.
+ *
+ * For example:
+ *
+ * trailing zeros: vvv vvvv
+ * const unsigned value = 0xF080; // 0000 0000 1111 0000 1000 0000
+ * int x = static_count_trailing_zeros<value>::value; // x = 7
+ *
+ * typedef mpl::integral_c<unsigned, 0xF080> value2;
+ * int y = mpl::count_trailing_zeros<value2>::value; // y = 7
+ *
+ */
+
+namespace boost {
+
+namespace mpl {
+
+/*
+ * MPL integral_c<> compatible version
+ */
+template <typename IC,
+ class Enable = typename enable_if< is_integral_constant<IC> >::type>
+struct count_trailing_zeros : pop_count< integral_c<uintmax_t, ~IC::value & (IC::value - 1)> >
+{};
+
+}
+
+template <uintmax_t Value>
+struct static_count_trailing_zeros :
+ mpl::count_trailing_zeros< mpl::integral_c<uintmax_t, Value> >
+{};
+
+} // boost
+
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk