Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67370 - sandbox/chrono/boost/static_integer
From: vicente.botet_at_[hidden]
Date: 2010-12-20 12:58:59


Author: viboes
Date: 2010-12-20 12:58:57 EST (Mon, 20 Dec 2010)
New Revision: 67370
URL: http://svn.boost.org/trac/boost/changeset/67370

Log:
StaticInteger: make static_abs work with msvc
Text files modified:
   sandbox/chrono/boost/static_integer/static_abs.hpp | 44 ++++++++++++++++++++++++++++++++-------
   1 files changed, 36 insertions(+), 8 deletions(-)

Modified: sandbox/chrono/boost/static_integer/static_abs.hpp
==============================================================================
--- sandbox/chrono/boost/static_integer/static_abs.hpp (original)
+++ sandbox/chrono/boost/static_integer/static_abs.hpp 2010-12-20 12:58:57 EST (Mon, 20 Dec 2010)
@@ -15,6 +15,7 @@
 
 #include <boost/cstdint.hpp>
 #include <boost/type_traits/integral_constant.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
 
 //
 // We simply cannot include this header on gcc without getting copious warnings of the kind:
@@ -33,25 +34,52 @@
 
 namespace integer
 {
+#if BOOST_RATIO_WORK_WITH_MSVC
     template <typename T, T X>
     struct static_abs
         : integral_constant<T,
- X < 0 ? -X : X>
+ (X < 0) ? -X : X>
     {};
-
+#else
     typedef boost::intmax_t static_abs_signed_type;
     typedef boost::uintmax_t static_abs_unsigned_type;
+ template <typename T, T X>
+ struct static_unary_minus;
+
+ template <static_abs_signed_type X>
+ struct static_unary_minus<static_abs_signed_type,X> : integral_constant<static_abs_signed_type, -X>
+ {};
 
+ namespace integer_detail
+ {
+ template <typename T, T X, bool LT0>
+ struct static_abs_aux2 : integral_constant<T, X>
+ {};
+ template <typename T, T X>
+ struct static_abs_aux2<T,X,true> : static_unary_minus<T, X>
+ {};
+ template <typename T, T X, bool IsUnsigned>
+ struct static_abs_aux : integral_constant<T, X>
+ {};
+ template <typename T, T X>
+ struct static_abs_aux<T,X,false> : static_abs_aux2<T, X, (X < 0) >
+ {};
+ }
+
+ template <typename T, T X>
+ struct static_abs : integer_detail::static_abs_aux<T, X, is_unsigned<T>::value >
+ {};
+
+#endif
+
     template <static_abs_signed_type X>
- struct static_signed_abs : static_abs<static_abs_signed_type, X>
- //~ : integral_constant<static_abs_signed_type,
- //~ X < 0 ? -X : X>
+ struct static_signed_abs
+ : static_abs<static_abs_signed_type, X>
     {};
 
     template <static_abs_signed_type X>
- struct static_unsigned_abs : static_abs<static_abs_signed_type, X>
- //~ : integral_constant<static_abs_unsigned_type,
- //~ X < 0 ? -X : X>
+ struct static_unsigned_abs
+ : static_abs<static_abs_unsigned_type, X>
     {};
 
 


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