Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63418 - in sandbox/SOC/2010/bits_and_ints: boost/integer libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-06-28 19:28:08


Author: murilov
Date: 2010-06-28 19:28:07 EDT (Mon, 28 Jun 2010)
New Revision: 63418
URL: http://svn.boost.org/trac/boost/changeset/63418

Log:
Updating static_bit_reversal: now it inherits from mpl::integral_c
Added a bit_reversal metafunction under mpl namespace wich accepts mpl::integral_c as template parameter
Text files modified:
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_bit_reversal.hpp | 36 +++++++++++++++++++++++++++++-------
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/bit_reversal_test.cpp | 9 +++++----
   2 files changed, 34 insertions(+), 11 deletions(-)

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/static_bit_reversal.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/static_bit_reversal.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_bit_reversal.hpp 2010-06-28 19:28:07 EDT (Mon, 28 Jun 2010)
@@ -13,6 +13,7 @@
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_integral.hpp>
 #include <boost/integer/detail/static_bit_reversal.hpp>
+#include <boost/mpl/integral_c.hpp>
 
 /*
  * Reverses the bits in data in compile-time
@@ -27,13 +28,34 @@
 
 // If T is an integral type, static_bit_reversal<T, data>::value will
 // be `data' with the bits reversed
-template <typename T, T data, class Enable = typename enable_if<is_integral<T> >::type>
-struct static_bit_reversal {
- BOOST_STATIC_CONSTANT(T, value =
- (integer_detail::static_bit_reversal_impl<T, data, sizeof(T) * 8>::value)
- );
-};
+template <typename T, T data, class Enable = typename enable_if< is_integral<T> >::type>
+struct static_bit_reversal : mpl::integral_c<T,
+ integer_detail::static_bit_reversal_impl<
+ T,
+ data,
+ sizeof(T) * 8
+ >::value
+>
+{}; // struct static_bit_reversal<>
+
+namespace mpl {
 
-} // boost
+/*
+ * Boost MPL compatible metafunctions
+ */
+
+template <typename IC>
+struct bit_reversal : integral_c<typename IC::value_type,
+ integer_detail::static_bit_reversal_impl<
+ typename IC::value_type,
+ IC::value, sizeof(typename IC::value_type) * 8
+ >::value
+>
+{}; // struct bit_reversal
+
+
+} // namespace mpl
+
+} // namespace boost
 
 #endif
\ No newline at end of file

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/bit_reversal_test.cpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/bit_reversal_test.cpp (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/bit_reversal_test.cpp 2010-06-28 19:28:07 EDT (Mon, 28 Jun 2010)
@@ -7,18 +7,19 @@
 
 #include <boost/detail/lightweight_test.hpp>
 
-#include <boost/cstdlib.hpp> // for boost::exit_success
+#include <boost/cstdlib.hpp>
 #include <boost/integer/bits_and_ints.hpp>
+#include <boost/mpl/integral_c.hpp>
 
-#include <iostream> // for std::cout (std::endl indirectly)
-
+#include <iostream>
 
 // Macros to compact code
 #define BIT_REVERSAL_TEST(n, m) \
         BOOST_TEST(::boost::bit_reversal(n) == m)
 
 #define STATIC_BIT_REVERSAL_TEST(t, n, m) \
- BOOST_TEST((::boost::static_bit_reversal<t, n>::value == m))
+ BOOST_TEST((::boost::static_bit_reversal<t, n>::value == m)); \
+ BOOST_TEST((::boost::mpl::bit_reversal< ::boost::mpl::integral_c<t, n> >::value == m))
 
 
 // Main testing function


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