Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67354 - sandbox/chrono/boost/static_integer
From: vicente.botet_at_[hidden]
Date: 2010-12-19 16:57:20


Author: viboes
Date: 2010-12-19 16:57:18 EST (Sun, 19 Dec 2010)
New Revision: 67354
URL: http://svn.boost.org/trac/boost/changeset/67354

Log:
StaticInteger make the operations a little more generic
Text files modified:
   sandbox/chrono/boost/static_integer/static_abs.hpp | 18 +++++++---
   sandbox/chrono/boost/static_integer/static_gcd.hpp | 62 ++++++++++++++++++++++++---------------
   sandbox/chrono/boost/static_integer/static_lcm.hpp | 27 +++++++++--------
   sandbox/chrono/boost/static_integer/static_sign.hpp | 28 ++++++++++-------
   4 files changed, 81 insertions(+), 54 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-19 16:57:18 EST (Sun, 19 Dec 2010)
@@ -33,19 +33,25 @@
 
 namespace integer
 {
+ template <typename T, T X>
+ struct static_abs
+ : integral_constant<T,
+ X < 0 ? -X : X>
+ {};
+
     typedef boost::intmax_t static_abs_signed_type;
     typedef boost::uintmax_t static_abs_unsigned_type;
 
     template <static_abs_signed_type X>
- struct static_signed_abs
- : integral_constant<static_abs_signed_type,
- X < 0 ? -X : X>
+ struct static_signed_abs : static_abs<static_abs_signed_type, X>
+ //~ : integral_constant<static_abs_signed_type,
+ //~ X < 0 ? -X : X>
     {};
 
     template <static_abs_signed_type X>
- struct static_unsigned_abs
- : integral_constant<static_abs_unsigned_type,
- X < 0 ? -X : X>
+ struct static_unsigned_abs : static_abs<static_abs_signed_type, X>
+ //~ : integral_constant<static_abs_unsigned_type,
+ //~ X < 0 ? -X : X>
     {};
 
 

Modified: sandbox/chrono/boost/static_integer/static_gcd.hpp
==============================================================================
--- sandbox/chrono/boost/static_integer/static_gcd.hpp (original)
+++ sandbox/chrono/boost/static_integer/static_gcd.hpp 2010-12-19 16:57:18 EST (Sun, 19 Dec 2010)
@@ -34,37 +34,51 @@
 namespace integer
 {
 
+namespace integer_detail
+{
+ template <typename T, bool X_is_0, T X, bool Y_is_0, T Y>
+ struct static_gcd_aux
+ : static_gcd_aux<T, Y==0, Y, (X % Y)==0, X % Y>
+ {};
+
+ template <typename T, T X, T Y>
+ struct static_gcd_aux<T, false, X, true, Y> : integral_constant<T, X>
+ {};
+
+ template <typename T, T X, T Y, bool C>
+ struct static_gcd_aux<T, true, X, C, Y> : integral_constant<T, Y>
+ {};
+}
+ template <typename T, T X, T Y>
+ struct static_gcd : integer_detail::static_gcd_aux<T, X==0, X, Y==0, Y>
+ {};
+
+ //~ template <typename T, T X, T Y>
+ //~ struct static_gcd
+ //~ : static_gcd<T, Y, X % Y>
+ //~ {};
+
+ //~ template <typename T, T X>
+ //~ struct static_gcd<T, X, T(0)> : integral_constant<T, X>
+ //~ {};
+
+ //~ template <typename T, T X>
+ //~ struct static_gcd<T, T(0), X> : integral_constant<T, X>
+ //~ {};
+
     typedef boost::intmax_t static_gcd_signed_type;
     typedef boost::uintmax_t static_gcd_unsigned_type;
 
- template <static_gcd_signed_type X, boost::intmax_t Y>
- struct static_signed_gcd
- : static_signed_gcd<Y, X % Y>
+
+ template <static_gcd_signed_type X, static_gcd_signed_type Y>
+ struct static_signed_gcd : static_gcd<static_gcd_signed_type, X, Y>
     {};
     
- template <static_gcd_signed_type X>
- struct static_signed_gcd<X, 0>
- : integral_constant<static_gcd_signed_type,
- X>
- {};
-
- template <static_gcd_signed_type X>
- struct static_signed_gcd<0, X>
- : integral_constant<static_gcd_signed_type,
- X>
- {};
-
- template <static_gcd_unsigned_type X, boost::intmax_t Y>
- struct static_unsigned_gcd
- : integral_constant<static_gcd_unsigned_type,
- static_unsigned_gcd<Y, X % Y>::value>
+
+ template <static_gcd_unsigned_type X, static_gcd_unsigned_type Y>
+ struct static_unsigned_gcd : static_gcd<static_gcd_unsigned_type, X, Y>
     {};
     
- template <static_gcd_unsigned_type X>
- struct static_unsigned_gcd<X, 0>
- : integral_constant<static_gcd_signed_type,
- X>
- {};
 }
 }
 

Modified: sandbox/chrono/boost/static_integer/static_lcm.hpp
==============================================================================
--- sandbox/chrono/boost/static_integer/static_lcm.hpp (original)
+++ sandbox/chrono/boost/static_integer/static_lcm.hpp 2010-12-19 16:57:18 EST (Sun, 19 Dec 2010)
@@ -34,22 +34,23 @@
 
 namespace integer
 {
+
+ template <typename T, T X, T Y>
+ struct static_lcm
+ : integral_constant<T,
+ X / static_gcd<T, X, Y>::value * Y>
+ {};
+
     typedef boost::intmax_t static_lcm_signed_type;
     typedef boost::uintmax_t static_lcm_unsigned_type;
 
- template <static_lcm_signed_type X, boost::intmax_t Y>
- struct static_signed_lcm
- : integral_constant<static_lcm_signed_type,
- X / static_signed_gcd<X, Y>::value * Y>
- {
- };
-
- template <static_lcm_unsigned_type X, boost::intmax_t Y>
- struct static_unsigned_lcm
- : integral_constant<static_lcm_unsigned_type,
- X / static_unsigned_gcd<X, Y>::value * Y>
- {
- };
+ template <static_lcm_signed_type X, static_lcm_signed_type Y>
+ struct static_signed_lcm : static_lcm<static_lcm_signed_type, X, Y>
+ {};
+
+ template <static_lcm_unsigned_type X, static_lcm_unsigned_type Y>
+ struct static_unsigned_lcm : static_lcm<static_lcm_unsigned_type, X, Y>
+ {};
 
 }
 }

Modified: sandbox/chrono/boost/static_integer/static_sign.hpp
==============================================================================
--- sandbox/chrono/boost/static_integer/static_sign.hpp (original)
+++ sandbox/chrono/boost/static_integer/static_sign.hpp 2010-12-19 16:57:18 EST (Sun, 19 Dec 2010)
@@ -33,20 +33,26 @@
 
 namespace integer
 {
+ template <typename T, T X>
+ struct static_sign
+ : integral_constant<T, X == 0 ? 0 : (X < 0 ? -1 : 1)>
+ {
+ };
+
     typedef boost::intmax_t static_sign_signed_type;
     typedef boost::intmax_t static_sign_unsigned_type;
 
- template <static_sign_signed_type X>
- struct static_signed_sign
- : integral_constant<static_sign_signed_type, X == 0 ? 0 : (X < 0 ? -1 : 1)>
- {
- };
-
- template <static_sign_unsigned_type X>
- struct static_unsigned_sign
- : integral_constant<static_sign_unsigned_type, X == 0 ? 0 : (X < 0 ? -1 : 1)>
- {
- };
+
+ template <static_sign_signed_type X>
+ struct static_signed_sign : static_sign<static_sign_signed_type, X>
+ {
+ };
+
+ template <static_sign_unsigned_type X>
+ struct static_unsigned_sign
+ : integral_constant<static_sign_unsigned_type, X == 0 ? 0 : 1>
+ {
+ };
 
 }
 }


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