Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63604 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-07-04 12:37:53


Author: murilov
Date: 2010-07-04 12:37:52 EDT (Sun, 04 Jul 2010)
New Revision: 63604
URL: http://svn.boost.org/trac/boost/changeset/63604

Log:
Added static_same_sign.hpp.
Now there is a mpl::same_sign<> wich works with mpl::integral_c<> template parameters
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_same_sign.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp | 1 +
   sandbox/SOC/2010/bits_and_ints/boost/integer/same_sign.hpp | 21 +++------------------
   2 files changed, 4 insertions(+), 18 deletions(-)

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp 2010-07-04 12:37:52 EDT (Sun, 04 Jul 2010)
@@ -19,6 +19,7 @@
 #include <boost/integer/static_bit_reversal.hpp>
 #include <boost/integer/sign.hpp>
 #include <boost/integer/same_sign.hpp>
+#include <boost/integer/static_same_sign.hpp>
 #include <boost/integer/pop_count.hpp>
 #include <boost/integer/interleave.hpp>
 #include <boost/integer/count_trailing_zeros.hpp>

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/same_sign.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/same_sign.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/same_sign.hpp 2010-07-04 12:37:52 EDT (Sun, 04 Jul 2010)
@@ -9,8 +9,6 @@
 
 #include <boost/type_traits/is_integral.hpp>
 #include <boost/utility/enable_if.hpp>
-#include <boost/integer/bit_utils.hpp>
-#include <limits>
 
 namespace boost
 {
@@ -19,6 +17,9 @@
  * same_sign(first, second) returns:
  * - false: if the signs of first and second are different
  * - true: if the signs are equal
+ *
+ * Note that 0 is not considered a positive nor negative integral, so
+ * same_sign(0, 1) is *false*.
  */
         
 template <typename T>
@@ -31,21 +32,5 @@
         
         return !temp;
 }
-
-/*
- * Compile-time version of same_sign
- *
- * static_same_sign<type, FIRST, SECOND>::value will be:
- * - false: if the signs of FIRST and SECOND are different
- * - true: if the signs are equal
- */
-template <typename T, T first, T second, class Enable = typename enable_if<is_integral<T> >::type>
-struct static_same_sign
-{
-private:
- static const int temp = (first ^ second) >> ((sizeof(T) * 8) - 1);
-public:
- BOOST_STATIC_CONSTANT(bool, value = !(temp & 1));
-};
         
 }
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/static_same_sign.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_same_sign.hpp 2010-07-04 12:37:52 EDT (Sun, 04 Jul 2010)
@@ -0,0 +1,52 @@
+// Boost integer/same_sign.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.
+
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/utility/enable_if.hpp>
+
+namespace boost {
+
+/*
+ * Compile-time version of same_sign.
+ * mpl::same_sign< integral_c<T, X>, integral_c<T, Y> >::value
+ * or static_same_sign<X, Y>::value will be:
+ * - false: if the signs of X and Y are different
+ * - true: if the signs are equal
+ *
+ * Note that 0 is not considered a positive nor negative integral, so
+ * static_same_sign<0, 1>::value is *false*.
+ */
+
+namespace mpl {
+
+/*
+ * MPL compatible static version of same_sign
+ * IC1 and IC2 types must be mpl::integral_c<> types.
+ */
+template <typename IC1, typename IC2>
+struct same_sign : bool_<((!IC1::value && !IC2::value)
+ || (IC1::value < 0 && IC2::value < 0)
+ || (IC2::value > 0 && IC2::value > 0))
+>
+{};
+
+}
+
+/*
+ * static_same_sign<type, FIRST, SECOND>::value will be:
+ * - false: if the signs of FIRST and SECOND are different
+ * - true: if the signs are equal
+ */
+template <typename T, T first, T second, class Enable = typename enable_if<is_integral<T> >::type>
+struct static_same_sign : mpl::same_sign< mpl::integral_c<T, first>, mpl::integral_c<T, second> >
+{};
+
+}
\ 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