|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63783 - in sandbox/SOC/2010/bits_and_ints: boost/integer libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-07-09 14:15:52
Author: murilov
Date: 2010-07-09 14:15:51 EDT (Fri, 09 Jul 2010)
New Revision: 63783
URL: http://svn.boost.org/trac/boost/changeset/63783
Log:
Added static_clear_least_bit_set<> and mpl::clear_least_bit_set<> metafunctions and its tests
Added:
sandbox/SOC/2010/bits_and_ints/boost/integer/static_clear_least_bit_set.hpp (contents, props changed)
sandbox/SOC/2010/bits_and_ints/libs/integer/test/clear_least_bit_set_test.cpp (contents, props changed)
Text files modified:
sandbox/SOC/2010/bits_and_ints/boost/integer/clear_least_bit_set.hpp | 2 +-
sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/clear_least_bit_set.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/clear_least_bit_set.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/clear_least_bit_set.hpp 2010-07-09 14:15:51 EDT (Fri, 09 Jul 2010)
@@ -26,7 +26,7 @@
{
return (value & (value - 1));
} //clear_least_bit_set
-
+
} //boost
#endif
Added: sandbox/SOC/2010/bits_and_ints/boost/integer/static_clear_least_bit_set.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_clear_least_bit_set.hpp 2010-07-09 14:15:51 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,55 @@
+// Boost integer/clear_least_bit_set.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_CLEAR_LEAST_BIT_SET
+#define BOOST_STATIC_CLEAR_LEAST_BIT_SET
+
+#include <boost/mpl/integral_c.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/integer/is_integral_constant.hpp>
+
+/*
+ * Clears last 1 bit in `value' in compile-time.
+ * For example:
+ *
+ * const int value = 0xFA; // 0000 0000 1111 1010
+ * const int x = static_clear_least_bit_set<value>::value;
+ * So x will be 0xF8 (0000 0000 1111 1000)
+ *
+ * For the MPL compatible:
+ *
+ * typedef mpl::integral_c<int, 0xFA> my_value;
+ * const int x = mpl::clear_least_bit_set<my_value>::value;
+ * `x' will be 0xF8 (0000 0000 1111 1000)
+ */
+
+namespace boost {
+
+namespace mpl {
+
+/*
+ * Requires IC to be a mpl::integral_c<> type
+ */
+template <typename IC,
+ class Enable = typename enable_if< is_integral_constant<IC> >::type>
+struct clear_least_bit_set : integral_c<typename IC::value_type, (IC::value & (IC::value - 1))>
+{};
+
+}
+
+/*
+ * Requires T to be an integral type
+ */
+template <typename T, T value>
+struct static_clear_least_bit_set : mpl::clear_least_bit_set< mpl::integral_c<T, value> >
+{};
+
+}
+
+#endif
Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 2010-07-09 14:15:51 EDT (Fri, 09 Jul 2010)
@@ -23,6 +23,7 @@
[ run static_lcm_test.cpp ]
[ run pop_count_test.cpp ]
[ run count_trailing_zeros_test.cpp ]
+ [ run clear_least_bit_set_test.cpp ]
[ compile cstdint_include_test.cpp ]
[ compile integer_traits_include_test.cpp ]
[ compile integer_include_test.cpp ]
Added: sandbox/SOC/2010/bits_and_ints/libs/integer/test/clear_least_bit_set_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/clear_least_bit_set_test.cpp 2010-07-09 14:15:51 EDT (Fri, 09 Jul 2010)
@@ -0,0 +1,47 @@
+// Boost clear_least_bit_set_test.hpp test program --------------------------------------//
+
+// (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
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/integer/clear_least_bit_set.hpp>
+#include <boost/integer/static_clear_least_bit_set.hpp>
+#include <boost/mpl/integral_c.hpp>
+
+#include <iostream>
+
+#define CLEAR_LEAST_BIT_SET_TEST(x, y) \
+BOOST_TEST((::boost::clear_least_bit_set(x) == y)); \
+BOOST_TEST(((::boost::mpl::clear_least_bit_set< ::boost::mpl::integral_c<int, x> >::value) == y))
+
+
+// Main testing function
+int main(int, char* [])
+{
+ std::cout << "Doing tests on pop_count functions." << std::endl;
+
+ CLEAR_LEAST_BIT_SET_TEST(0x0, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x1, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x2, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x4, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x8, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x3, 2);
+ CLEAR_LEAST_BIT_SET_TEST(0x5, 4);
+ CLEAR_LEAST_BIT_SET_TEST(0x9, 8);
+ CLEAR_LEAST_BIT_SET_TEST(0x90, 0x80);
+ CLEAR_LEAST_BIT_SET_TEST(0xAA, 0xA8);
+ CLEAR_LEAST_BIT_SET_TEST(0xFFFF, 0xFFFE);
+ CLEAR_LEAST_BIT_SET_TEST(0xF0A0, 0xF080);
+ CLEAR_LEAST_BIT_SET_TEST(0xFFFFFFFF, 0xFFFFFFFE);
+ CLEAR_LEAST_BIT_SET_TEST(0x55555555, 0x55555554);
+ CLEAR_LEAST_BIT_SET_TEST(0xBABEBEEF, 0xBABEBEEE);
+ CLEAR_LEAST_BIT_SET_TEST(0xFF800, 0xFF000);
+ CLEAR_LEAST_BIT_SET_TEST(0x800, 0);
+ CLEAR_LEAST_BIT_SET_TEST(0x123800, 0x123000);
+ CLEAR_LEAST_BIT_SET_TEST(0x33800, 0x33000);
+ CLEAR_LEAST_BIT_SET_TEST(0x82000000, 0x80000000);
+
+ return boost::report_errors();
+}
\ No newline at end of file
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