Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67578 - in trunk/boost/ratio: . detail
From: vicente.botet_at_[hidden]
Date: 2011-01-02 12:06:48


Author: viboes
Date: 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
New Revision: 67578
URL: http://svn.boost.org/trac/boost/changeset/67578

Log:
Boost.Ratio: moved to trunk
Added:
   trunk/boost/ratio/
   trunk/boost/ratio/detail/
   trunk/boost/ratio/detail/overflow_helpers.hpp (contents, props changed)
   trunk/boost/ratio/ratio.hpp (contents, props changed)
   trunk/boost/ratio/ratio_fwd.hpp (contents, props changed)
   trunk/boost/ratio/ratio_io.hpp (contents, props changed)
   trunk/boost/ratio/ratio_static_string.hpp (contents, props changed)

Added: trunk/boost/ratio/detail/overflow_helpers.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/ratio/detail/overflow_helpers.hpp 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
@@ -0,0 +1,379 @@
+// ratio.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 Krugler,
+ Anthony Williams.
+*/
+
+// The way overflow is managed for ratio_less is taken from llvm/libcxx/include/ratio
+
+#ifndef BOOST_RATIO_DETAIL_RATIO_OPERATIONS_HPP
+#define BOOST_RATIO_DETAIL_RATIO_OPERATIONS_HPP
+
+//~ #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 <boost/mpl/abs.hpp>
+#include <boost/mpl/sign.hpp>
+//~ #include <boost/mpl/gcd.hpp>
+//~ #include <boost/mpl/lcm.hpp>
+#include <cstdlib>
+#include <climits>
+#include <limits>
+#include <boost/cstdint.hpp>
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/integer_traits.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT) || !defined(BOOST_RATIO_USES_MPL_ASSERT)
+#define BOOST_RATIO_OVERFLOW_IN_ADD "overflow in ratio add"
+#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_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
+#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
+#elif defined(BOOST_RATIO_USES_STATIC_ASSERT)
+#include <boost/static_assert.hpp>
+#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
+#elif defined(BOOST_RATIO_USES_MPL_ASSERT)
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) \
+ BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
+#else
+//~ #elif defined(BOOST_RATIO_USES_ARRAY_ASSERT)
+#define BOOST_RATIO_CONCAT(A,B) A##B
+#define BOOST_RATIO_NAME(A,B) BOOST_RATIO_CONCAT(A,B)
+#define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_RATIO_NAME(__boost_ratio_test_,__LINE__)[(CND)?1:-1]
+//~ #define BOOST_RATIO_STATIC_ASSERT(CND, MSG, TYPES)
+#endif
+
+
+//
+// We simply cannot include this header on gcc without getting copious warnings of the kind:
+//
+// boost/integer.hpp:77:30: warning: use of C99 long long integer constant
+//
+// And yet there is no other reasonable implementation, so we declare this a system header
+// to suppress these warnings.
+//
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#pragma GCC system_header
+#endif
+
+namespace boost
+{
+
+//----------------------------------------------------------------------------//
+// helpers //
+//----------------------------------------------------------------------------//
+
+namespace ratio_detail
+{
+
+ template <boost::intmax_t X, boost::intmax_t Y, boost::intmax_t = mpl::sign_c<boost::intmax_t, Y>::value>
+ class br_add;
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_add<X, Y, 1>
+ {
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ BOOST_RATIO_STATIC_ASSERT(X <= max - Y , BOOST_RATIO_OVERFLOW_IN_ADD, ());
+ public:
+ static const boost::intmax_t value = X + Y;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_add<X, Y, 0>
+ {
+ public:
+ static const boost::intmax_t value = X;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_add<X, Y, -1>
+ {
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ BOOST_RATIO_STATIC_ASSERT(min - Y <= X, BOOST_RATIO_OVERFLOW_IN_ADD, ());
+ public:
+ static const boost::intmax_t value = X + Y;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y, boost::intmax_t = mpl::sign_c<boost::intmax_t, Y>::value>
+ class br_sub;
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_sub<X, Y, 1>
+ {
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ BOOST_RATIO_STATIC_ASSERT(min + Y <= X, BOOST_RATIO_OVERFLOW_IN_SUB, ());
+ public:
+ static const boost::intmax_t value = X - Y;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_sub<X, Y, 0>
+ {
+ public:
+ static const boost::intmax_t value = X;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_sub<X, Y, -1>
+ {
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ BOOST_RATIO_STATIC_ASSERT(X <= max + Y, BOOST_RATIO_OVERFLOW_IN_SUB, ());
+ public:
+ static const boost::intmax_t value = X - Y;
+ };
+
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_mul
+ {
+ static const boost::intmax_t nan =
+ (BOOST_RATIO_INTMAX_C(1) << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ static const boost::intmax_t a_x = mpl::abs_c<boost::intmax_t, X>::value;
+ static const boost::intmax_t a_y = mpl::abs_c<boost::intmax_t, Y>::value;
+
+ BOOST_RATIO_STATIC_ASSERT(X != nan, BOOST_RATIO_OVERFLOW_IN_MUL, ());
+ BOOST_RATIO_STATIC_ASSERT(Y != nan, BOOST_RATIO_OVERFLOW_IN_MUL, ());
+ BOOST_RATIO_STATIC_ASSERT(a_x <= max / a_y, BOOST_RATIO_OVERFLOW_IN_MUL, ());
+ public:
+ static const boost::intmax_t value = X * Y;
+ };
+
+ template <boost::intmax_t Y>
+ class br_mul<0, Y>
+ {
+ public:
+ static const boost::intmax_t value = 0;
+ };
+
+ template <boost::intmax_t X>
+ class br_mul<X, 0>
+ {
+ public:
+ static const boost::intmax_t value = 0;
+ };
+
+ template <>
+ class br_mul<0, 0>
+ {
+ public:
+ static const boost::intmax_t value = 0;
+ };
+
+ // Not actually used but left here in case needed in future maintenance
+ template <boost::intmax_t X, boost::intmax_t Y>
+ class br_div
+ {
+ static const boost::intmax_t nan = (1LL << (sizeof(boost::intmax_t) * CHAR_BIT - 1));
+ static const boost::intmax_t min = boost::integer_traits<boost::intmax_t>::const_min;
+ static const boost::intmax_t max = boost::integer_traits<boost::intmax_t>::const_max;
+
+ 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_DIVIDE_BY_0, ());
+ public:
+ static const boost::intmax_t value = X / Y;
+ };
+
+ // 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;
+
+ template <class R1, class R2>
+ struct ratio_add
+ {
+ //The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value R1::num *
+ //R2::den + R2::num * R1::den and T2 has the value R1::den * R2::den.
+ // As the preceding doesn't works because of overflow on boost::intmax_t we need something more elaborated.
+ private:
+ static const boost::intmax_t gcd_n1_n2 = mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value;
+ static const boost::intmax_t gcd_d1_d2 = mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value;
+ public:
+ // No need to normalize as ratio_multiply is already normalized
+ typedef typename ratio_multiply
+ <
+ ratio<gcd_n1_n2, R1::den / gcd_d1_d2>,
+ ratio
+ <
+ boost::ratio_detail::br_add
+ <
+ boost::ratio_detail::br_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+ boost::ratio_detail::br_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+ >::value,
+ R2::den
+ >
+ >::type type;
+ };
+
+ template <class R1, class R2>
+ struct ratio_subtract
+ {
+ //The nested typedef type shall be a synonym for ratio<T1, T2>::type where T1 has the value
+ // R1::num *R2::den - R2::num * R1::den and T2 has the value R1::den * R2::den.
+ // As the preceding doesn't works because of overflow on boost::intmax_t we need something more elaborated.
+ private:
+ static const boost::intmax_t gcd_n1_n2 = mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value;
+ static const boost::intmax_t gcd_d1_d2 = mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value;
+ public:
+ // No need to normalize as ratio_multiply is already normalized
+ typedef typename ratio_multiply
+ <
+ ratio<gcd_n1_n2, R1::den / gcd_d1_d2>,
+ ratio
+ <
+ boost::ratio_detail::br_sub
+ <
+ boost::ratio_detail::br_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+ boost::ratio_detail::br_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+ >::value,
+ R2::den
+ >
+ >::type type;
+ };
+
+ template <class R1, class R2>
+ struct ratio_multiply
+ {
+ // The nested typedef type shall be a synonym for ratio<R1::num * R2::den - R2::num * R1::den, R1::den * R2::den>::type.
+ // As the preceding doesn't works because of overflow on boost::intmax_t we need something more elaborated.
+ private:
+ static const boost::intmax_t gcd_n1_d2 = mpl::gcd_c<boost::intmax_t, R1::num, R2::den>::value;
+ static const boost::intmax_t gcd_d1_n2 = mpl::gcd_c<boost::intmax_t, R1::den, R2::num>::value;
+ public:
+ typedef typename ratio
+ <
+ boost::ratio_detail::br_mul<R1::num / gcd_n1_d2, R2::num / gcd_d1_n2>::value,
+ boost::ratio_detail::br_mul<R2::den / gcd_n1_d2, R1::den / gcd_d1_n2>::value
+ >::type type;
+ };
+
+ template <class R1, class R2>
+ struct ratio_divide
+ {
+ // The nested typedef type shall be a synonym for ratio<R1::num * R2::den, R2::num * R1::den>::type.
+ // As the preceding doesn't works because of overflow on boost::intmax_t we need something more elaborated.
+ private:
+ static const boost::intmax_t gcd_n1_n2 = mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value;
+ static const boost::intmax_t gcd_d1_d2 = mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value;
+ public:
+ typedef typename ratio
+ <
+ boost::ratio_detail::br_mul<R1::num / gcd_n1_n2, R2::den / gcd_d1_d2>::value,
+ boost::ratio_detail::br_mul<R2::num / gcd_n1_n2, R1::den / gcd_d1_d2>::value
+ >::type type;
+ };
+
+ template <class T>
+ 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 R1, class R2,
+ boost::intmax_t Q1 = R1::num / R1::den, boost::intmax_t M1 = R1::num % R1::den,
+ boost::intmax_t Q2 = R2::num / R2::den, boost::intmax_t M2 = R2::num % R2::den>
+ struct ratio_less1
+ {
+ static const bool value = Q1 < Q2;
+ };
+
+ template <class R1, class R2, boost::intmax_t Q>
+ struct ratio_less1<R1, R2, Q, 0, Q, 0>
+ {
+ static const bool value = false;
+ };
+
+ template <class R1, class R2, boost::intmax_t Q, boost::intmax_t M2>
+ struct ratio_less1<R1, R2, Q, 0, Q, M2>
+ {
+ static const bool value = true;
+ };
+
+ template <class R1, class R2, boost::intmax_t Q, boost::intmax_t M1>
+ struct ratio_less1<R1, R2, Q, M1, Q, 0>
+ {
+ static const bool value = false;
+ };
+
+ template <class R1, class R2, boost::intmax_t Q, boost::intmax_t M1, boost::intmax_t M2>
+ struct ratio_less1<R1, R2, Q, M1, Q, M2>
+ {
+ static const bool value = ratio_less1<ratio<R2::den, M2>, ratio<R1::den, M1>
+ >::value;
+ };
+
+ template <
+ class R1,
+ class R2,
+ boost::intmax_t S1 = mpl::sign_c<boost::intmax_t, R1::num>::value,
+ boost::intmax_t S2 = mpl::sign_c<boost::intmax_t, R2::num>::value
+>
+ struct ratio_less
+ {
+ static const bool value = S1 < S2;
+ };
+
+ template <class R1, class R2>
+ struct ratio_less<R1, R2, 1LL, 1LL>
+ {
+ static const bool value = ratio_less1<R1, R2>::value;
+ };
+
+ template <class R1, class R2>
+ struct ratio_less<R1, R2, -1LL, -1LL>
+ {
+ static const bool value = ratio_less1<ratio<-R2::num, R2::den>,
+ ratio<-R1::num, R1::den> >::value;
+ };
+
+
+} // namespace ratio_detail
+
+} // namespace boost
+
+#endif // BOOST_RATIO_HPP

Added: trunk/boost/ratio/ratio.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/ratio/ratio.hpp 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
@@ -0,0 +1,226 @@
+// ratio.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 Krugler,
+ Anthony Williams.
+*/
+
+// The way overflow is managed for ratio_less is taken from llvm/libcxx/include/ratio
+
+#ifndef BOOST_RATIO_RATIO_HPP
+#define BOOST_RATIO_RATIO_HPP
+
+#include <boost/config.hpp>
+#include <boost/mpl/abs.hpp>
+#include <boost/mpl/sign.hpp>
+#include <boost/mpl/gcd.hpp>
+#include <boost/mpl/lcm.hpp>
+#include <cstdlib>
+#include <climits>
+#include <limits>
+#include <boost/cstdint.hpp>
+#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>
+#ifdef BOOST_RATIO_EXTENSIONS
+#include <boost/rational.hpp>
+#include <boost/ratio/mpl/rational_c_tag.hpp>
+#endif
+
+//
+// We simply cannot include this header on gcc without getting copious warnings of the kind:
+//
+// boost/integer.hpp:77:30: warning: use of C99 long long integer constant
+//
+// And yet there is no other reasonable implementation, so we declare this a system header
+// to suppress these warnings.
+//
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#pragma GCC system_header
+#endif
+
+namespace boost
+{
+
+
+//----------------------------------------------------------------------------//
+// //
+// 20.6.1 Class template ratio [ratio.ratio] //
+// //
+//----------------------------------------------------------------------------//
+
+template <boost::intmax_t N, boost::intmax_t D>
+class ratio
+{
+ static const boost::intmax_t ABS_N = mpl::abs_c<boost::intmax_t, N>::value;
+ static const boost::intmax_t ABS_D = mpl::abs_c<boost::intmax_t, D>::value;
+ 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_N = mpl::sign_c<boost::intmax_t,N>::value
+ * mpl::sign_c<boost::intmax_t,D>::value;
+ static const boost::intmax_t GCD = mpl::gcd_c<boost::intmax_t, ABS_N, ABS_D>::value;
+public:
+ BOOST_STATIC_CONSTEXPR boost::intmax_t num = SIGN_N * ABS_N / GCD;
+ BOOST_STATIC_CONSTEXPR boost::intmax_t den = ABS_D / GCD;
+
+#ifdef BOOST_RATIO_EXTENSIONS
+ typedef mpl::rational_c_tag tag;
+ typedef boost::rational<boost::intmax_t> value_type;
+ typedef boost::intmax_t num_type;
+ typedef boost::intmax_t den_type;
+ ratio()
+ {}
+ template <boost::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)
+ {}
+
+ template <boost::intmax_t _N2, boost::intmax_t _D2>
+ typename enable_if_c
+ <
+ (ratio<_N2, _D2>::num == num &&
+ ratio<_N2, _D2>::den == den),
+ ratio&
+ >::type
+ operator=(const ratio<_N2, _D2>&) {return *this;}
+
+ static value_type value() {return value_type(num,den);}
+ value_type operator()() const {return value();}
+#endif
+ typedef ratio<num, den> type;
+};
+
+//----------------------------------------------------------------------------//
+// //
+// 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
+// //
+//----------------------------------------------------------------------------//
+
+template <class R1, class R2>
+struct ratio_add
+: boost::ratio_detail::ratio_add<R1, R2>::type
+{
+};
+
+template <class R1, class R2>
+struct ratio_subtract
+: boost::ratio_detail::ratio_subtract<R1, R2>::type
+{
+};
+
+template <class R1, class R2>
+struct ratio_multiply
+: boost::ratio_detail::ratio_multiply<R1, R2>::type
+{
+};
+
+template <class R1, class R2>
+struct ratio_divide
+: boost::ratio_detail::ratio_divide<R1, R2>::type
+{
+};
+
+//----------------------------------------------------------------------------//
+// //
+// 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)>
+{};
+
+template <class R1, class R2>
+struct ratio_not_equal
+ : 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>
+{};
+
+template <class R1, class R2>
+struct ratio_less_equal
+ : 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>
+{};
+
+template <class R1, class R2>
+struct ratio_greater_equal
+ : boost::integral_constant<bool, !ratio_less<R1, R2>::value>
+{};
+
+template <class R1, class R2>
+struct ratio_gcd :
+ ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
+ mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type
+{
+};
+
+#ifdef BOOST_RATIO_EXTENSIONS
+template <class R>
+struct ratio_negate
+ : ratio<-R::num, R::den>::type
+{
+};
+template <class R>
+struct ratio_abs
+ : ratio<mpl::abs_c<boost::intmax_t, R::num>::value, R::den>::type
+{
+};
+template <class R>
+struct ratio_sign
+ : mpl::sign_c<boost::intmax_t, R::num>
+{
+};
+template <class R1, class R2>
+struct ratio_lcm :
+ ratio<mpl::lcm_c<boost::intmax_t, R1::num, R2::num>::value,
+ mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value>::type
+{
+};
+#endif
+} // namespace boost
+
+
+#endif // BOOST_RATIO_RATIO_HPP

Added: trunk/boost/ratio/ratio_fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/ratio/ratio_fwd.hpp 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
@@ -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 Krugler,
+ 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_RATIO_INTMAX_C(a) INTMAX_C(a)
+#else
+#define BOOST_RATIO_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_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000000)> atto;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000000)> femto;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000000)> pico;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000000)> nano;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000000)> micro;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(1000)> milli;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(100)> centi;
+typedef ratio<BOOST_RATIO_INTMAX_C(1), BOOST_RATIO_INTMAX_C(10)> deci;
+typedef ratio< BOOST_RATIO_INTMAX_C(10), BOOST_RATIO_INTMAX_C(1)> deca;
+typedef ratio< BOOST_RATIO_INTMAX_C(100), BOOST_RATIO_INTMAX_C(1)> hecto;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000), BOOST_RATIO_INTMAX_C(1)> kilo;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000), BOOST_RATIO_INTMAX_C(1)> mega;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000), BOOST_RATIO_INTMAX_C(1)> giga;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000), BOOST_RATIO_INTMAX_C(1)> tera;
+typedef ratio< BOOST_RATIO_INTMAX_C(1000000000000000), BOOST_RATIO_INTMAX_C(1)> peta;
+typedef ratio<BOOST_RATIO_INTMAX_C(1000000000000000000), BOOST_RATIO_INTMAX_C(1)> exa;
+
+} // namespace boost
+
+
+#endif // BOOST_RATIO_HPP

Added: trunk/boost/ratio/ratio_io.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/ratio/ratio_io.hpp 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
@@ -0,0 +1,793 @@
+// ratio_io
+//
+// (C) Copyright Howard Hinnant
+// (C) Copyright 2010 Vicente J. Botet Escriba
+// Use, modification and distribution are subject to 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).
+//
+// This code was adapted by Vicente from Howard Hinnant's experimental work
+// on chrono i/o under lvm/libc++ to Boost
+
+#ifndef BOOST_RATIO_RATIO_IO_HPP
+#define BOOST_RATIO_RATIO_IO_HPP
+
+/*
+
+ ratio_io synopsis
+
+#include <ratio>
+#include <string>
+
+namespace boost
+{
+
+template <class Ratio, class CharT>
+struct ratio_string
+{
+ static basic_string<CharT> short_name();
+ static basic_string<CharT> long_name();
+};
+
+} // boost
+
+*/
+
+#include <boost/config.hpp>
+#include <boost/ratio.hpp>
+#include <string>
+#include <sstream>
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+#include <boost/ratio/ratio_static_string.hpp>
+#include <boost/static_string/static_string.hpp>
+#endif
+
+#if defined(BOOST_NO_UNICODE_LITERALS) || defined(BOOST_NO_CHAR16_T) || defined(BOOST_NO_CHAR32_T)
+//~ #define BOOST_RATIO_HAS_UNICODE_SUPPORT
+#else
+#define BOOST_RATIO_HAS_UNICODE_SUPPORT 1
+#endif
+
+namespace boost {
+
+template <class Ratio, class CharT>
+struct ratio_string
+{
+ static std::basic_string<CharT> short_name() {return long_name();}
+ static std::basic_string<CharT> long_name();
+};
+
+template <class Ratio, class CharT>
+std::basic_string<CharT>
+ratio_string<Ratio, CharT>::long_name()
+{
+ std::basic_ostringstream<CharT> os;
+ os << CharT('[') << Ratio::num << CharT('/')
+ << Ratio::den << CharT(']');
+ return os.str();
+}
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+namespace ratio_detail {
+template <class Ratio, class CharT>
+struct ratio_string_static
+{
+ static std::string short_name() {
+ return std::basic_string<CharT>(
+ static_string::c_str<
+ typename ratio_static_string<Ratio, CharT>::short_name
+ >::value);
+ }
+ static std::string long_name() {
+ return std::basic_string<CharT>(
+ static_string::c_str<
+ typename ratio_static_string<Ratio, CharT>::long_name
+ >::value);
+ }
+};
+}
+#endif
+// atto
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<atto, CharT> :
+ ratio_detail::ratio_string_static<atto,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<atto, char>
+{
+ static std::string short_name() {return std::string(1, 'a');}
+ static std::string long_name() {return std::string("atto");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<atto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'a');}
+ static std::u16string long_name() {return std::u16string(u"atto");}
+};
+
+template <>
+struct ratio_string<atto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'a');}
+ static std::u32string long_name() {return std::u32string(U"atto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<atto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'a');}
+ static std::wstring long_name() {return std::wstring(L"atto");}
+};
+#endif
+#endif
+
+// femto
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<femto, CharT> :
+ ratio_detail::ratio_string_static<femto,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<femto, char>
+{
+ static std::string short_name() {return std::string(1, 'f');}
+ static std::string long_name() {return std::string("femto");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<femto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'f');}
+ static std::u16string long_name() {return std::u16string(u"femto");}
+};
+
+template <>
+struct ratio_string<femto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'f');}
+ static std::u32string long_name() {return std::u32string(U"femto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<femto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'f');}
+ static std::wstring long_name() {return std::wstring(L"femto");}
+};
+#endif
+#endif
+
+// pico
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<pico, CharT> :
+ ratio_detail::ratio_string_static<pico,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<pico, char>
+{
+ static std::string short_name() {return std::string(1, 'p');}
+ static std::string long_name() {return std::string("pico");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<pico, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'p');}
+ static std::u16string long_name() {return std::u16string(u"pico");}
+};
+
+template <>
+struct ratio_string<pico, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'p');}
+ static std::u32string long_name() {return std::u32string(U"pico");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<pico, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'p');}
+ static std::wstring long_name() {return std::wstring(L"pico");}
+};
+#endif
+#endif
+
+// nano
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<nano, CharT> :
+ ratio_detail::ratio_string_static<nano,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<nano, char>
+{
+ static std::string short_name() {return std::string(1, 'n');}
+ static std::string long_name() {return std::string("nano");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<nano, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'n');}
+ static std::u16string long_name() {return std::u16string(u"nano");}
+};
+
+template <>
+struct ratio_string<nano, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'n');}
+ static std::u32string long_name() {return std::u32string(U"nano");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<nano, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'n');}
+ static std::wstring long_name() {return std::wstring(L"nano");}
+};
+#endif
+#endif
+
+// micro
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<micro, CharT> :
+ ratio_detail::ratio_string_static<micro,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<micro, char>
+{
+ static std::string short_name() {return std::string("\xC2\xB5");}
+ static std::string long_name() {return std::string("micro");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<micro, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'\xB5');}
+ static std::u16string long_name() {return std::u16string(u"micro");}
+};
+
+template <>
+struct ratio_string<micro, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'\xB5');}
+ static std::u32string long_name() {return std::u32string(U"micro");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<micro, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'\xB5');}
+ static std::wstring long_name() {return std::wstring(L"micro");}
+};
+#endif
+#endif
+
+// milli
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<milli, CharT> :
+ ratio_detail::ratio_string_static<milli,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<milli, char>
+{
+ static std::string short_name() {return std::string(1, 'm');}
+ static std::string long_name() {return std::string("milli");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<milli, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'm');}
+ static std::u16string long_name() {return std::u16string(u"milli");}
+};
+
+template <>
+struct ratio_string<milli, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'm');}
+ static std::u32string long_name() {return std::u32string(U"milli");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<milli, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'm');}
+ static std::wstring long_name() {return std::wstring(L"milli");}
+};
+#endif
+#endif
+
+// centi
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<centi, CharT> :
+ ratio_detail::ratio_string_static<centi,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<centi, char>
+{
+ static std::string short_name() {return std::string(1, 'c');}
+ static std::string long_name() {return std::string("centi");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<centi, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'c');}
+ static std::u16string long_name() {return std::u16string(u"centi");}
+};
+
+template <>
+struct ratio_string<centi, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'c');}
+ static std::u32string long_name() {return std::u32string(U"centi");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<centi, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'c');}
+ static std::wstring long_name() {return std::wstring(L"centi");}
+};
+#endif
+#endif
+
+// deci
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<deci, CharT> :
+ ratio_detail::ratio_string_static<deci,CharT>
+{};
+
+#else
+
+template <>
+struct ratio_string<deci, char>
+{
+ static std::string short_name() {return std::string(1, 'd');}
+ static std::string long_name() {return std::string("deci");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<deci, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'd');}
+ static std::u16string long_name() {return std::u16string(u"deci");}
+};
+
+template <>
+struct ratio_string<deci, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'd');}
+ static std::u32string long_name() {return std::u32string(U"deci");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<deci, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'd');}
+ static std::wstring long_name() {return std::wstring(L"deci");}
+};
+#endif
+#endif
+
+// deca
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<deca, CharT> :
+ ratio_detail::ratio_string_static<deca,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<deca, char>
+{
+ static std::string short_name() {return std::string("da");}
+ static std::string long_name() {return std::string("deca");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<deca, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(u"da");}
+ static std::u16string long_name() {return std::u16string(u"deca");}
+};
+
+template <>
+struct ratio_string<deca, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(U"da");}
+ static std::u32string long_name() {return std::u32string(U"deca");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<deca, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(L"da");}
+ static std::wstring long_name() {return std::wstring(L"deca");}
+};
+#endif
+#endif
+
+// hecto
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<hecto, CharT> :
+ ratio_detail::ratio_string_static<hecto,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<hecto, char>
+{
+ static std::string short_name() {return std::string(1, 'h');}
+ static std::string long_name() {return std::string("hecto");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<hecto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'h');}
+ static std::u16string long_name() {return std::u16string(u"hecto");}
+};
+
+template <>
+struct ratio_string<hecto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'h');}
+ static std::u32string long_name() {return std::u32string(U"hecto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<hecto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'h');}
+ static std::wstring long_name() {return std::wstring(L"hecto");}
+};
+#endif
+#endif
+
+// kilo
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<kilo, CharT> :
+ ratio_detail::ratio_string_static<kilo,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<kilo, char>
+{
+ static std::string short_name() {return std::string(1, 'k');}
+ static std::string long_name() {return std::string("kilo");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<kilo, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'k');}
+ static std::u16string long_name() {return std::u16string(u"kilo");}
+};
+
+template <>
+struct ratio_string<kilo, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'k');}
+ static std::u32string long_name() {return std::u32string(U"kilo");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<kilo, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'k');}
+ static std::wstring long_name() {return std::wstring(L"kilo");}
+};
+#endif
+#endif
+
+// mega
+
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<mega, CharT> :
+ ratio_detail::ratio_string_static<mega,CharT>
+{};
+
+#else
+
+template <>
+struct ratio_string<mega, char>
+{
+ static std::string short_name() {return std::string(1, 'M');}
+ static std::string long_name() {return std::string("mega");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<mega, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'M');}
+ static std::u16string long_name() {return std::u16string(u"mega");}
+};
+
+template <>
+struct ratio_string<mega, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'M');}
+ static std::u32string long_name() {return std::u32string(U"mega");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<mega, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'M');}
+ static std::wstring long_name() {return std::wstring(L"mega");}
+};
+#endif
+#endif
+
+// giga
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<giga, CharT> :
+ ratio_detail::ratio_string_static<giga,CharT>
+{};
+
+#else
+
+template <>
+struct ratio_string<giga, char>
+{
+ static std::string short_name() {return std::string(1, 'G');}
+ static std::string long_name() {return std::string("giga");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<giga, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'G');}
+ static std::u16string long_name() {return std::u16string(u"giga");}
+};
+
+template <>
+struct ratio_string<giga, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'G');}
+ static std::u32string long_name() {return std::u32string(U"giga");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<giga, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'G');}
+ static std::wstring long_name() {return std::wstring(L"giga");}
+};
+#endif
+#endif
+
+// tera
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<tera, CharT> :
+ ratio_detail::ratio_string_static<tera,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<tera, char>
+{
+ static std::string short_name() {return std::string(1, 'T');}
+ static std::string long_name() {return std::string("tera");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<tera, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'T');}
+ static std::u16string long_name() {return std::u16string(u"tera");}
+};
+
+template <>
+struct ratio_string<tera, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'T');}
+ static std::u32string long_name() {return std::u32string(U"tera");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<tera, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'T');}
+ static std::wstring long_name() {return std::wstring(L"tera");}
+};
+#endif
+#endif
+
+// peta
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<peta, CharT> :
+ ratio_detail::ratio_string_static<peta,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<peta, char>
+{
+ static std::string short_name() {return std::string(1, 'P');}
+ static std::string long_name() {return std::string("peta");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<peta, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'P');}
+ static std::u16string long_name() {return std::u16string(u"peta");}
+};
+
+template <>
+struct ratio_string<peta, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'P');}
+ static std::u32string long_name() {return std::u32string(U"peta");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<peta, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'P');}
+ static std::wstring long_name() {return std::wstring(L"peta");}
+};
+#endif
+#endif
+
+// exa
+#ifdef BOOST_RATIO_HAS_STATIC_STRING
+template <typename CharT>
+struct ratio_string<exa, CharT> :
+ ratio_detail::ratio_string_static<exa,CharT>
+{};
+
+#else
+template <>
+struct ratio_string<exa, char>
+{
+ static std::string short_name() {return std::string(1, 'E');}
+ static std::string long_name() {return std::string("exa");}
+};
+
+#if BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<exa, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'E');}
+ static std::u16string long_name() {return std::u16string(u"exa");}
+};
+
+template <>
+struct ratio_string<exa, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'E');}
+ static std::u32string long_name() {return std::u32string(U"exa");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<exa, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'E');}
+ static std::wstring long_name() {return std::wstring(L"exa");}
+};
+#endif
+#endif
+
+}
+
+#endif // BOOST_RATIO_RATIO_IO_HPP

Added: trunk/boost/ratio/ratio_static_string.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/ratio/ratio_static_string.hpp 2011-01-02 12:06:40 EST (Sun, 02 Jan 2011)
@@ -0,0 +1,631 @@
+// ratio_io
+//
+// (C) Copyright 2010 Vicente J. Botet Escriba
+// Use, modification and distribution are subject to 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).
+//
+// This code was adapted by Vicente from Howard Hinnant's experimental work
+// on chrono i/o under lvm/libc++ to Boost
+
+#ifndef BOOST_RATIO_RATIO_STATIC_STRING_HPP
+#define BOOST_RATIO_RATIO_STATIC_STRING_HPP
+
+/*
+
+ ratio_static_string synopsis
+
+#include <ratio>
+#include <string>
+
+namespace boost
+{
+
+template <class Ratio, class CharT>
+struct ratio_static_string
+{
+ typedef basic_str<CharT, ...> short_name;
+ typedef basic_str<CharT, ...> long_name;
+};
+
+} // boost
+
+*/
+
+#include <boost/config.hpp>
+#include <boost/ratio.hpp>
+#include <boost/static_string/basic_str.hpp>
+//#include <sstream>
+
+
+#if defined(BOOST_NO_UNICODE_LITERALS) || defined(BOOST_NO_CHAR16_T) || defined(BOOST_NO_CHAR32_T)
+//~ #define BOOST_RATIO_HAS_UNICODE_SUPPORT
+#else
+#define BOOST_RATIO_HAS_UNICODE_SUPPORT 1
+#endif
+
+namespace boost {
+
+template <class Ratio, class CharT>
+struct ratio_static_string;
+
+
+// atto
+
+template <>
+struct ratio_static_string<atto, char>
+{
+ typedef static_string::str_1<'a'>::type short_name;
+ typedef static_string::str_4<'a','t','t','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<atto, char16_t>
+{
+ typedef static_string::u16str_1<u'a'>::type short_name;
+ typedef static_string::u16str_4<u'a',u't',u't',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<atto, char32_t>
+{
+ typedef static_string::u32str_1<U'a'>::type short_name;
+ typedef static_string::u32str_4<U'a',U't',U't',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<atto, wchar_t>
+{
+ typedef static_string::wstr_1<L'a'>::type short_name;
+ typedef static_string::wstr_4<L'a',L't',L't',L'o'>::type long_name;
+};
+#endif
+
+// femto
+
+template <>
+struct ratio_static_string<femto, char>
+{
+ typedef static_string::str_1<'f'>::type short_name;
+ typedef static_string::str_5<'f','e','m','t','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<femto, char16_t>
+{
+ typedef static_string::u16str_1<u'f'>::type short_name;
+ typedef static_string::u16str_5<u'f',u'e',u'm',u't',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<femto, char32_t>
+{
+ typedef static_string::u32str_1<U'f'>::type short_name;
+ typedef static_string::u32str_5<U'f',U'e',U'm',U't',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<femto, wchar_t>
+{
+ typedef static_string::wstr_1<L'f'>::type short_name;
+ typedef static_string::wstr_5<L'f',L'e',L'm',L't',L'o'>::type long_name;
+};
+#endif
+
+// pico
+
+template <>
+struct ratio_static_string<pico, char>
+{
+ typedef static_string::str_1<'p'>::type short_name;
+ typedef static_string::str_4<'p','i','c','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<pico, char16_t>
+{
+ typedef static_string::u16str_1<u'p'>::type short_name;
+ typedef static_string::u16str_4<u'p',u'i',u'c',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<pico, char32_t>
+{
+ typedef static_string::u32str_1<U'p'>::type short_name;
+ typedef static_string::u32str_4<U'p',U'i',U'c',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<pico, wchar_t>
+{
+ typedef static_string::wstr_1<L'p'>::type short_name;
+ typedef static_string::wstr_4<L'p',L'i',L'c',L'o'>::type long_name;
+};
+#endif
+
+// nano
+
+template <>
+struct ratio_static_string<nano, char>
+{
+ typedef static_string::str_1<'n'>::type short_name;
+ typedef static_string::str_4<'n','a','n','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<nano, char16_t>
+{
+ typedef static_string::u16str_1<u'n'>::type short_name;
+ typedef static_string::u16str_4<u'n',u'a',u'n',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<nano, char32_t>
+{
+ typedef static_string::u32str_1<U'n'>::type short_name;
+ typedef static_string::u32str_4<U'n',U'a',U'n',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<nano, wchar_t>
+{
+ typedef static_string::wstr_1<L'n'>::type short_name;
+ typedef static_string::wstr_4<L'n',L'a',L'n',L'o'>::type long_name;
+};
+#endif
+
+// micro
+
+template <>
+struct ratio_static_string<micro, char>
+{
+ typedef static_string::str_2<'\xC2','\xB5'>::type short_name;
+ typedef static_string::str_5<'m','i','c','r','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<micro, char16_t>
+{
+ typedef static_string::u16str_1<u'\xB5'>::type short_name;
+ typedef static_string::u16str_5<u'm',u'i',u'c',u'r',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<micro, char32_t>
+{
+ typedef static_string::u32str_1<U'\xB5'>::type short_name;
+ typedef static_string::u32str_5<U'm',U'i',U'c',U'r',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<micro, wchar_t>
+{
+ typedef static_string::wstr_1<L'\xB5'>::type short_name;
+ typedef static_string::wstr_5<L'm',L'i',L'c',L'r',L'o'>::type long_name;
+};
+#endif
+
+// milli
+
+template <>
+struct ratio_static_string<milli, char>
+{
+ typedef static_string::str_1<'m'>::type short_name;
+ typedef static_string::str_5<'m','i','l','l','i'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<milli, char16_t>
+{
+ typedef static_string::u16str_1<u'm'>::type short_name;
+ typedef static_string::u16str_5<u'm',u'i',u'l',u'l',u'i'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<milli, char32_t>
+{
+ typedef static_string::u32str_1<U'm'>::type short_name;
+ typedef static_string::u32str_5<U'm',U'i',U'l',U'l',U'i'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<milli, wchar_t>
+{
+ typedef static_string::wstr_1<L'm'>::type short_name;
+ typedef static_string::wstr_5<L'm',L'i',L'l',L'l',L'i'>::type long_name;
+};
+#endif
+
+// centi
+
+template <>
+struct ratio_static_string<centi, char>
+{
+ typedef static_string::str_1<'c'>::type short_name;
+ typedef static_string::str_5<'c','e','n','t','i'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<centi, char16_t>
+{
+ typedef static_string::u16str_1<u'c'>::type short_name;
+ typedef static_string::u16str_5<u'c',u'e',u'n',u't',u'i'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<centi, char32_t>
+{
+ typedef static_string::u32str_1<U'c'>::type short_name;
+ typedef static_string::u32str_5<U'c',U'e',U'n',U't',U'i'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<centi, wchar_t>
+{
+ typedef static_string::wstr_1<L'c'>::type short_name;
+ typedef static_string::wstr_5<L'c',L'e',L'n',L't',L'i'>::type long_name;
+};
+#endif
+
+// deci
+
+template <>
+struct ratio_static_string<deci, char>
+{
+ typedef static_string::str_1<'d'>::type short_name;
+ typedef static_string::str_4<'d','e','c','i'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<deci, char16_t>
+{
+ typedef static_string::u16str_1<u'd'>::type short_name;
+ typedef static_string::u16str_4<u'd',u'e',u'c',u'i'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<deci, char32_t>
+{
+ typedef static_string::u32str_1<U'd'>::type short_name;
+ typedef static_string::u32str_4<U'd',U'e',U'c',U'i'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<deci, wchar_t>
+{
+ typedef static_string::wstr_1<L'd'>::type short_name;
+ typedef static_string::wstr_4<L'd',L'e',L'c',L'i'>::type long_name;
+};
+#endif
+
+// deca
+
+template <>
+struct ratio_static_string<deca, char>
+{
+ typedef static_string::str_2<'d','a'>::type short_name;
+ typedef static_string::str_4<'d','e','c','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<deca, char16_t>
+{
+ typedef static_string::u16str_2<u'd',u'a'>::type short_name;
+ typedef static_string::u16str_4<u'd',u'e',u'c',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<deca, char32_t>
+{
+ typedef static_string::u32str_2<U'd',U'a'>::type short_name;
+ typedef static_string::u32str_4<U'd',U'e',U'c',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<deca, wchar_t>
+{
+ typedef static_string::wstr_2<L'd',L'a'>::type short_name;
+ typedef static_string::wstr_4<L'd',L'e',L'c',L'a'>::type long_name;
+};
+#endif
+
+// hecto
+
+template <>
+struct ratio_static_string<hecto, char>
+{
+ typedef static_string::str_1<'h'>::type short_name;
+ typedef static_string::str_5<'h','e','c','t','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<hecto, char16_t>
+{
+ typedef static_string::u16str_1<u'h'>::type short_name;
+ typedef static_string::u16str_5<u'h',u'e',u'c',u't',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<hecto, char32_t>
+{
+ typedef static_string::u32str_1<U'h'>::type short_name;
+ typedef static_string::u32str_5<U'h',U'e',U'c',U't',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<hecto, wchar_t>
+{
+ typedef static_string::wstr_1<L'h'>::type short_name;
+ typedef static_string::wstr_5<L'h',L'e',L'c',L't',L'o'>::type long_name;
+};
+#endif
+
+// kilo
+
+template <>
+struct ratio_static_string<kilo, char>
+{
+ typedef static_string::str_1<'k'>::type short_name;
+ typedef static_string::str_4<'k','i','l','o'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<kilo, char16_t>
+{
+ typedef static_string::u16str_1<u'k'>::type short_name;
+ typedef static_string::u16str_4<u'k',u'i',u'l',u'o'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<kilo, char32_t>
+{
+ typedef static_string::u32str_1<U'k'>::type short_name;
+ typedef static_string::u32str_4<U'k',U'i',U'l',U'o'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<kilo, wchar_t>
+{
+ typedef static_string::wstr_1<L'k'>::type short_name;
+ typedef static_string::wstr_4<L'k',L'i',L'l',L'o'>::type long_name;
+};
+#endif
+
+// mega
+
+template <>
+struct ratio_static_string<mega, char>
+{
+ typedef static_string::str_1<'M'>::type short_name;
+ typedef static_string::str_4<'m','e','g','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<mega, char16_t>
+{
+ typedef static_string::u16str_1<u'M'>::type short_name;
+ typedef static_string::u16str_4<u'm',u'e',u'g',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<mega, char32_t>
+{
+ typedef static_string::u32str_1<U'M'>::type short_name;
+ typedef static_string::u32str_4<U'm',U'e',U'g',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<mega, wchar_t>
+{
+ typedef static_string::wstr_1<L'M'>::type short_name;
+ typedef static_string::wstr_4<L'm',L'e',L'g',L'a'>::type long_name;
+};
+#endif
+
+// giga
+
+template <>
+struct ratio_static_string<giga, char>
+{
+ typedef static_string::str_1<'G'>::type short_name;
+ typedef static_string::str_4<'g','i','g','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<giga, char16_t>
+{
+ typedef static_string::u16str_1<u'G'>::type short_name;
+ typedef static_string::u16str_4<u'g',u'i',u'g',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<giga, char32_t>
+{
+ typedef static_string::u32str_1<U'G'>::type short_name;
+ typedef static_string::u32str_4<U'g',U'i',U'g',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<giga, wchar_t>
+{
+ typedef static_string::wstr_1<L'G'>::type short_name;
+ typedef static_string::wstr_4<L'g',L'i',L'g',L'a'>::type long_name;
+};
+#endif
+
+// tera
+
+template <>
+struct ratio_static_string<tera, char>
+{
+ typedef static_string::str_1<'T'>::type short_name;
+ typedef static_string::str_4<'t','e','r','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<tera, char16_t>
+{
+ typedef static_string::u16str_1<u'T'>::type short_name;
+ typedef static_string::u16str_4<u't',u'e',u'r',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<tera, char32_t>
+{
+ typedef static_string::u32str_1<U'T'>::type short_name;
+ typedef static_string::u32str_4<U't',U'e',U'r',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<tera, wchar_t>
+{
+ typedef static_string::wstr_1<L'T'>::type short_name;
+ typedef static_string::wstr_4<L'r',L'e',L'r',L'a'>::type long_name;
+};
+#endif
+
+// peta
+
+template <>
+struct ratio_static_string<peta, char>
+{
+ typedef static_string::str_1<'P'>::type short_name;
+ typedef static_string::str_4<'p','e','t','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<peta, char16_t>
+{
+ typedef static_string::u16str_1<u'P'>::type short_name;
+ typedef static_string::u16str_4<u'p',u'e',u't',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<peta, char32_t>
+{
+ typedef static_string::u32str_1<U'P'>::type short_name;
+ typedef static_string::u32str_4<U'p',U'e',U't',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<peta, wchar_t>
+{
+ typedef static_string::wstr_1<L'P'>::type short_name;
+ typedef static_string::wstr_4<L'p',L'e',L't',L'a'>::type long_name;
+};
+#endif
+
+// exa
+
+template <>
+struct ratio_static_string<exa, char>
+{
+ typedef static_string::str_1<'E'>::type short_name;
+ typedef static_string::str_3<'e','x','a'>::type long_name;
+};
+
+#ifdef BOOST_RATIO_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_static_string<exa, char16_t>
+{
+ typedef static_string::u16str_1<u'E'>::type short_name;
+ typedef static_string::u16str_3<u'e',u'x',u'a'>::type long_name;
+};
+
+template <>
+struct ratio_static_string<exa, char32_t>
+{
+ typedef static_string::u32str_1<U'E'>::type short_name;
+ typedef static_string::u32str_3<U'e',U'x',U'a'>::type long_name;
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_static_string<exa, wchar_t>
+{
+ typedef static_string::wstr_1<L'E'>::type short_name;
+ typedef static_string::wstr_3<L'e',L'x',L'a'>::type long_name;
+};
+#endif
+
+}
+
+#endif // BOOST_RATIO_RATIO_STATIC_STRING_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