Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63494 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-07-02 14:54:36


Author: murilov
Date: 2010-07-01 13:42:09 EDT (Thu, 01 Jul 2010)
New Revision: 63494
URL: http://svn.boost.org/trac/boost/changeset/63494

Log:
Added mpl::sign_extend metafunctions wich accepts mpl::integral_c as template parameter.
static_sign_extend is now implemented in terms of mpl version.
Text files modified:
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_bit_reversal.hpp | 3 ++-
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_sign_extend.hpp | 34 +++++++++++++++++++++++-----------
   2 files changed, 25 insertions(+), 12 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-07-01 13:42:09 EDT (Thu, 01 Jul 2010)
@@ -29,7 +29,8 @@
 namespace mpl {
 
 /*
- * Boost MPL compatible metafunctions
+ * Boost MPL compatible metafunctions
+ * IC is a mpl::integral_c<> type
  */
 
 template <typename IC>

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/static_sign_extend.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/static_sign_extend.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_sign_extend.hpp 2010-07-01 13:42:09 EDT (Thu, 01 Jul 2010)
@@ -12,9 +12,10 @@
 
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_integral.hpp>
+#include <boost/mpl/integral_c.hpp>
 
 /*
- * Extend `data' represented in `Bits' bits to sizeof(Type) * 8
+ * Extend `data' represented in `Bits' bits to sizeof(T) * 8
  * in compile-time.
  *
  * For example if binary representation of `data' in 4 bits is:
@@ -31,18 +32,29 @@
 
 namespace boost
 {
+
+namespace mpl {
+
+/*
+ * Boost MPL compatible metafunction
+ * IC is a mpl::integral_c<> type
+ */
+
+template <typename IC, std::size_t Bits>
+struct sign_extend : integral_c<typename IC::value_type,
+ (((IC::value & ((typename IC::value_type(1) << Bits) - 1))
+ ^ (typename IC::value_type(1) << (Bits - 1)))
+ - (typename IC::value_type(1) << (Bits - 1)))
+>
+{};
+
+}
 
 // Compile-time version of sign_extend
-template<typename Type, Type data, std::size_t Bits,
- class Enable = typename enable_if<is_integral<Type> >::type>
-struct static_sign_extend
-{
-private:
- BOOST_STATIC_CONSTANT(Type, shift = (Type(1) << (Bits - 1)));
- BOOST_STATIC_CONSTANT(Type, mask = ((Type(1) << Bits) - 1));
-public:
- BOOST_STATIC_CONSTANT(Type, value = ((data & mask) ^ shift) - shift);
-}; // boost::static_sign_extend
+template<typename T, T data, std::size_t Bits,
+ class Enable = typename enable_if< is_integral<T> >::type>
+struct static_sign_extend : mpl::sign_extend<mpl::integral_c<T, data>, Bits>
+{}; // boost::static_sign_extend
 
 } // boost
 


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