|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65918 - in sandbox/chrono/boost/ratio: . detail
From: vicente.botet_at_[hidden]
Date: 2010-10-11 19:12:17
Author: viboes
Date: 2010-10-11 19:12:16 EDT (Mon, 11 Oct 2010)
New Revision: 65918
URL: http://svn.boost.org/trac/boost/changeset/65918
Log:
Ratio:
* Extract forward declarations
* Change RATIO_RATIO
Added:
sandbox/chrono/boost/ratio/ratio_fwd.hpp (contents, props changed)
Text files modified:
sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp | 22 ++++-------
sandbox/chrono/boost/ratio/ratio.hpp | 80 ++++++++++++++--------------------------
2 files changed, 36 insertions(+), 66 deletions(-)
Modified: sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp
==============================================================================
--- sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp (original)
+++ sandbox/chrono/boost/ratio/detail/overflow_helpers.hpp 2010-10-11 19:12:16 EDT (Mon, 11 Oct 2010)
@@ -49,9 +49,9 @@
#define BOOST_RATIO_OVERFLOW_IN_SUB "overflow in ratio sub"
#define BOOST_RATIO_OVERFLOW_IN_MUL "overflow in ratio mul"
#define BOOST_RATIO_OVERFLOW_IN_DIV "overflow in ratio div"
-#define BOOST_RATIO_RATIO_NUMERATOR_IS_OUT_OF_RANGE "ratio numerator is out of range"
-#define BOOST_RATIO_RATIO_DIVIDE_BY_0 "ratio divide by 0"
-#define BOOST_RATIO_RATIO_DENOMINATOR_IS_OUT_OF_RANGE "ratio denominator is out of range"
+#define BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE "ratio numerator is out of range"
+#define BOOST_RATIO_DIVIDE_BY_0 "ratio divide by 0"
+#define BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE "ratio denominator is out of range"
#endif
#ifndef BOOST_NO_STATIC_ASSERT
@@ -73,11 +73,6 @@
#endif
-#ifdef INTMAX_C
-#define BOOST_INTMAX_C(a) INTMAX_C(a)
-#else
-#define BOOST_INTMAX_C(a) a##LL
-#endif
//
// We simply cannot include this header on gcc without getting copious warnings of the kind:
//
@@ -92,7 +87,6 @@
namespace boost
{
-template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;
//----------------------------------------------------------------------------//
// helpers //
@@ -214,7 +208,7 @@
BOOST_RATIO_STATIC_ASSERT(X != nan, BOOST_RATIO_OVERFLOW_IN_DIV, ());
BOOST_RATIO_STATIC_ASSERT(Y != nan, BOOST_RATIO_OVERFLOW_IN_DIV, ());
- BOOST_RATIO_STATIC_ASSERT(Y != 0, BOOST_RATIO_RATIO_DIVIDE_BY_0, ());
+ BOOST_RATIO_STATIC_ASSERT(Y != 0, BOOST_RATIO_DIVIDE_BY_0, ());
public:
static const boost::intmax_t value = X / Y;
};
@@ -310,11 +304,11 @@
};
template <class T>
- struct is_ratio : public boost::false_type {};
+ struct is_ratio : public boost::false_type
+ {};
template <boost::intmax_t N, boost::intmax_t D>
- struct is_ratio<ratio<N, D> > : public boost::true_type {};
- //template <class T>
- // struct is_ratio : is_ratio<typename remove_cv<T>::type> {};
+ struct is_ratio<ratio<N, D> > : public boost::true_type
+ {};
template <class R1, class R2,
boost::intmax_t Q1 = R1::num / R1::den, boost::intmax_t M1 = R1::num % R1::den,
Modified: sandbox/chrono/boost/ratio/ratio.hpp
==============================================================================
--- sandbox/chrono/boost/ratio/ratio.hpp (original)
+++ sandbox/chrono/boost/ratio/ratio.hpp 2010-10-11 19:12:16 EDT (Mon, 11 Oct 2010)
@@ -34,7 +34,6 @@
#include <boost/static_integer/static_abs.hpp>
#include <boost/static_integer/static_sign.hpp>
-//#include <boost/static_integer/static_lcm.hpp>
#include <boost/static_integer/static_gcd.hpp>
#include <cstdlib>
#include <climits>
@@ -43,6 +42,7 @@
#include <boost/type_traits/integral_constant.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/integer_traits.hpp>
+#include <boost/ratio/ratio_fwd.hpp>
#include <boost/ratio/detail/overflow_helpers.hpp>
//
@@ -60,48 +60,10 @@
namespace boost
{
-//----------------------------------------------------------------------------//
-// //
-// 20.4 Compile-time rational arithmetic [ratio] //
-// //
-//----------------------------------------------------------------------------//
-
-// ratio arithmetic
-template <class R1, class R2> struct ratio_add;
-template <class R1, class R2> struct ratio_subtract;
-template <class R1, class R2> struct ratio_multiply;
-template <class R1, class R2> struct ratio_divide;
-
-// ratio comparison
-template <class R1, class R2> struct ratio_equal;
-template <class R1, class R2> struct ratio_not_equal;
-template <class R1, class R2> struct ratio_less;
-template <class R1, class R2> struct ratio_less_equal;
-template <class R1, class R2> struct ratio_greater;
-template <class R1, class R2> struct ratio_greater_equal;
-
-// convenience SI typedefs
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000000)> atto;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000)> femto;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000)> pico;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000)> nano;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000)> micro;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000)> milli;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(100)> centi;
-typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10)> deci;
-typedef ratio< BOOST_INTMAX_C(10), BOOST_INTMAX_C(1)> deca;
-typedef ratio< BOOST_INTMAX_C(100), BOOST_INTMAX_C(1)> hecto;
-typedef ratio< BOOST_INTMAX_C(1000), BOOST_INTMAX_C(1)> kilo;
-typedef ratio< BOOST_INTMAX_C(1000000), BOOST_INTMAX_C(1)> mega;
-typedef ratio< BOOST_INTMAX_C(1000000000), BOOST_INTMAX_C(1)> giga;
-typedef ratio< BOOST_INTMAX_C(1000000000000), BOOST_INTMAX_C(1)> tera;
-typedef ratio< BOOST_INTMAX_C(1000000000000000), BOOST_INTMAX_C(1)> peta;
-typedef ratio<BOOST_INTMAX_C(1000000000000000000), BOOST_INTMAX_C(1)> exa;
-
//----------------------------------------------------------------------------//
// //
-// 20.4.1 Class template ratio [ratio.ratio] //
+// 20.6.1 Class template ratio [ratio.ratio] //
// //
//----------------------------------------------------------------------------//
@@ -110,9 +72,9 @@
{
static const boost::intmax_t ABS_N = boost::integer::static_signed_abs<N>::value;
static const boost::intmax_t ABS_D = boost::integer::static_signed_abs<D>::value;
- BOOST_RATIO_STATIC_ASSERT(ABS_N >= 0, BOOST_RATIO_RATIO_NUMERATOR_IS_OUT_OF_RANGE, ());
- BOOST_RATIO_STATIC_ASSERT(ABS_D > 0, BOOST_RATIO_RATIO_DENOMINATOR_IS_OUT_OF_RANGE, ());
- BOOST_RATIO_STATIC_ASSERT(D != 0, BOOST_RATIO_RATIO_DIVIDE_BY_0 , ());
+ BOOST_RATIO_STATIC_ASSERT(ABS_N >= 0, BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE, ());
+ BOOST_RATIO_STATIC_ASSERT(ABS_D > 0, BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE, ());
+ BOOST_RATIO_STATIC_ASSERT(D != 0, BOOST_RATIO_DIVIDE_BY_0 , ());
static const boost::intmax_t SIGN = boost::integer::static_signed_sign<N>::value
* boost::integer::static_signed_sign<D>::value;
static const boost::intmax_t GCD = boost::integer::static_signed_gcd<ABS_N, ABS_D>::value;
@@ -121,14 +83,16 @@
static const boost::intmax_t den = ABS_D / GCD;
#ifdef BOOST_RATIO_EXTENSIONS
- ratio() {}
+ ratio()
+ {}
template <intmax_t _N2, boost::intmax_t _D2>
ratio(const ratio<_N2, _D2>&,
typename enable_if_c
<
(ratio<_N2, _D2>::num == num &&
ratio<_N2, _D2>::den == den)
- >::type* = 0) {}
+ >::type* = 0)
+ {}
template <intmax_t _N2, boost::intmax_t _D2>
typename enable_if_c
@@ -144,7 +108,7 @@
//----------------------------------------------------------------------------//
// //
-// Implementation //
+// 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
// //
//----------------------------------------------------------------------------//
@@ -172,34 +136,46 @@
{
};
+//----------------------------------------------------------------------------//
+// //
+// 20.6.3 Comparasion of ratio types [ratio.comparison] //
+// //
+//----------------------------------------------------------------------------//
+
// ratio_equal
template <class R1, class R2>
struct ratio_equal
: public boost::integral_constant<bool,
- (R1::num == R2::num && R1::den == R2::den)> {};
+ (R1::num == R2::num && R1::den == R2::den)>
+{};
template <class R1, class R2>
struct ratio_not_equal
- : public boost::integral_constant<bool, !ratio_equal<R1, R2>::value> {};
+ : public boost::integral_constant<bool, !ratio_equal<R1, R2>::value>
+{};
// ratio_less
template <class R1, class R2>
struct ratio_less
- : boost::integral_constant<bool, boost::ratio_detail::ratio_less<R1, R2>::value> {};
+ : boost::integral_constant<bool, boost::ratio_detail::ratio_less<R1, R2>::value>
+{};
template <class R1, class R2>
struct ratio_less_equal
- : boost::integral_constant<bool, !ratio_less<R2, R1>::value> {};
+ : boost::integral_constant<bool, !ratio_less<R2, R1>::value>
+{};
template <class R1, class R2>
struct ratio_greater
- : boost::integral_constant<bool, ratio_less<R2, R1>::value> {};
+ : boost::integral_constant<bool, ratio_less<R2, R1>::value>
+{};
template <class R1, class R2>
struct ratio_greater_equal
- : boost::integral_constant<bool, !ratio_less<R1, R2>::value> {};
+ : boost::integral_constant<bool, !ratio_less<R1, R2>::value>
+{};
template <class R1, class R2>
struct ratio_gcd
Added: sandbox/chrono/boost/ratio/ratio_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/ratio/ratio_fwd.hpp 2010-10-11 19:12:16 EDT (Mon, 11 Oct 2010)
@@ -0,0 +1,89 @@
+// ratio_fwd.hpp ---------------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+/*
+
+This code was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.4 Compile-time rational arithmetic [ratio], of the C++ committee working
+paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+// The way overflow is managed for ratio_less is taken from llvm/libcxx/include/ratio
+
+#ifndef BOOST_RATIO_RATIO_FWD_HPP
+#define BOOST_RATIO_RATIO_FWD_HPP
+
+#include <boost/cstdint.hpp>
+#ifdef INTMAX_C
+#define BOOST_INTMAX_C(a) INTMAX_C(a)
+#else
+#define BOOST_INTMAX_C(a) a##LL
+#endif
+
+namespace boost
+{
+
+//----------------------------------------------------------------------------//
+// //
+// 20.6 Compile-time rational arithmetic [ratio] //
+// //
+//----------------------------------------------------------------------------//
+
+// ratio
+template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;
+
+// ratio arithmetic
+template <class R1, class R2> struct ratio_add;
+template <class R1, class R2> struct ratio_subtract;
+template <class R1, class R2> struct ratio_multiply;
+template <class R1, class R2> struct ratio_divide;
+
+// ratio comparison
+template <class R1, class R2> struct ratio_equal;
+template <class R1, class R2> struct ratio_not_equal;
+template <class R1, class R2> struct ratio_less;
+template <class R1, class R2> struct ratio_less_equal;
+template <class R1, class R2> struct ratio_greater;
+template <class R1, class R2> struct ratio_greater_equal;
+
+// convenience SI typedefs
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000000)> atto;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000000)> femto;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000000)> pico;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000000)> nano;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000000)> micro;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(1000)> milli;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(100)> centi;
+typedef ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10)> deci;
+typedef ratio< BOOST_INTMAX_C(10), BOOST_INTMAX_C(1)> deca;
+typedef ratio< BOOST_INTMAX_C(100), BOOST_INTMAX_C(1)> hecto;
+typedef ratio< BOOST_INTMAX_C(1000), BOOST_INTMAX_C(1)> kilo;
+typedef ratio< BOOST_INTMAX_C(1000000), BOOST_INTMAX_C(1)> mega;
+typedef ratio< BOOST_INTMAX_C(1000000000), BOOST_INTMAX_C(1)> giga;
+typedef ratio< BOOST_INTMAX_C(1000000000000), BOOST_INTMAX_C(1)> tera;
+typedef ratio< BOOST_INTMAX_C(1000000000000000), BOOST_INTMAX_C(1)> peta;
+typedef ratio<BOOST_INTMAX_C(1000000000000000000), BOOST_INTMAX_C(1)> exa;
+
+} // namespace boost
+
+
+#endif // BOOST_RATIO_HPP
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