Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65623 - sandbox/chrono/libs/ratio/example
From: vicente.botet_at_[hidden]
Date: 2010-09-27 07:26:42


Author: viboes
Date: 2010-09-27 07:26:38 EDT (Mon, 27 Sep 2010)
New Revision: 65623
URL: http://svn.boost.org/trac/boost/changeset/65623

Log:
Ratio. remove dependency to chrono/duration.hpp file
Added:
   sandbox/chrono/libs/ratio/example/config.hpp (contents, props changed)
   sandbox/chrono/libs/ratio/example/duration.hpp (contents, props changed)
   sandbox/chrono/libs/ratio/example/static_assert.hpp (contents, props changed)
Text files modified:
   sandbox/chrono/libs/ratio/example/si_physics.cpp | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

Added: sandbox/chrono/libs/ratio/example/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/ratio/example/config.hpp 2010-09-27 07:26:38 EDT (Mon, 27 Sep 2010)
@@ -0,0 +1,123 @@
+// boost/chrono/config.hpp -------------------------------------------------//
+
+// Copyright Beman Dawes 2003, 2006, 2008
+// Copyright 2009 Vicente J. Botet Escriba
+
+// 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/libs/chrono for documentation.
+
+#ifndef BOOST_CHRONO_CONFIG_HPP
+#define BOOST_CHRONO_CONFIG_HPP
+
+#include <boost/config.hpp>
+
+// BOOST_CHRONO_POSIX_API, BOOST_CHRONO_MAC_API, or BOOST_CHRONO_WINDOWS_API
+// can be defined by the user to specify which API should be used
+
+#if defined(BOOST_CHRONO_WINDOWS_API)
+# warning Boost.Chrono will use the Windows API
+#elif defined(BOOST_CHRONO_MAC_API)
+# warning Boost.Chrono will use the Mac API
+#elif defined(BOOST_CHRONO_POSIX_API)
+# warning Boost.Chrono will use the POSIX API
+#endif
+
+# if defined( BOOST_CHRONO_WINDOWS_API ) && defined( BOOST_CHRONO_POSIX_API )
+# error both BOOST_CHRONO_WINDOWS_API and BOOST_CHRONO_POSIX_API are defined
+# elif defined( BOOST_CHRONO_WINDOWS_API ) && defined( BOOST_CHRONO_MAC_API )
+# error both BOOST_CHRONO_WINDOWS_API and BOOST_CHRONO_MAC_API are defined
+# elif defined( BOOST_CHRONO_MAC_API ) && defined( BOOST_CHRONO_POSIX_API )
+# error both BOOST_CHRONO_MAC_API and BOOST_CHRONO_POSIX_API are defined
+# elif !defined( BOOST_CHRONO_WINDOWS_API ) && !defined( BOOST_CHRONO_MAC_API ) && !defined( BOOST_CHRONO_POSIX_API )
+# if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
+# define BOOST_CHRONO_WINDOWS_API
+# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+# define BOOST_CHRONO_HAS_THREAD_CLOCK
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
+# elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+# define BOOST_CHRONO_MAC_API
+# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
+# else
+# define BOOST_CHRONO_POSIX_API
+# endif
+# endif
+
+# if defined( BOOST_CHRONO_POSIX_API )
+# include <time.h> //to check for CLOCK_REALTIME and CLOCK_MONOTONIC and _POSIX_THREAD_CPUTIME
+# if defined(CLOCK_REALTIME)
+# if defined(CLOCK_MONOTONIC)
+# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+# endif
+# else
+# error <time.h> does not supply CLOCK_REALTIME
+# endif
+# if defined(_POSIX_THREAD_CPUTIME)
+# define BOOST_CHRONO_HAS_THREAD_CLOCK
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
+# endif
+# endif
+
+
+
+// enable dynamic linking on Windows ---------------------------------------//
+
+//# if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CHRONO_DYN_LINK)) && defined(__BORLANDC__) && defined(__WIN32__)
+//# error Dynamic linking Boost.System does not work for Borland; use static linking instead
+//# endif
+
+#ifdef BOOST_HAS_DECLSPEC // defined by boost.config
+// we need to import/export our code only if the user has specifically
+// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
+// libraries to be dynamically linked, or BOOST_CHRONO_DYN_LINK
+// if they want just this one to be dynamically liked:
+#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CHRONO_DYN_LINK)
+// export if this is our own source, otherwise import:
+#ifdef BOOST_CHRONO_SOURCE
+# define BOOST_CHRONO_DECL __declspec(dllexport)
+#else
+# define BOOST_CHRONO_DECL __declspec(dllimport)
+#endif // BOOST_CHRONO_SOURCE
+#endif // DYN_LINK
+#endif // BOOST_HAS_DECLSPEC
+//
+// if BOOST_CHRONO_DECL isn't defined yet define it now:
+#ifndef BOOST_CHRONO_DECL
+#define BOOST_CHRONO_DECL
+#endif
+
+// define constexpr related macros ------------------------------//
+
+//~ #include <boost/config.hpp>
+#if defined(BOOST_NO_CONSTEXPR)
+#define BOOST_CHRONO_CONSTEXPR
+#define BOOST_CHRONO_CONST_REF const&
+#else
+#define BOOST_CHRONO_CONSTEXPR constexpr
+#define BOOST_CHRONO_CONST_REF
+#endif
+
+// enable automatic library variant selection ------------------------------//
+
+#if !defined(BOOST_CHRONO_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_CHRONO_NO_LIB)
+//
+// Set the name of our library; this will get undef'ed by auto_link.hpp
+// once it's done with it:
+//
+#define BOOST_LIB_NAME boost_chrono
+//
+// If we're importing code from a dll, then tell auto_link.hpp about it:
+//
+#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CHRONO_DYN_LINK)
+# define BOOST_DYN_LINK
+#endif
+//
+// And include the header that does the work:
+//
+#include <boost/config/auto_link.hpp>
+#endif // auto-linking disabled
+
+#endif // BOOST_CHRONO_CONFIG_HPP
+

Added: sandbox/chrono/libs/ratio/example/duration.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/ratio/example/duration.hpp 2010-09-27 07:26:38 EDT (Mon, 27 Sep 2010)
@@ -0,0 +1,792 @@
+// duration.hpp --------------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// Copyright 2009-2010 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.9 Time utilities [time] of the C++ committee's 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.
+*/
+
+
+#ifndef BOOST_CHRONO_DURATION_HPP
+#define BOOST_CHRONO_DURATION_HPP
+
+#include "config.hpp"
+#include "static_assert.hpp"
+
+//~ #include <iostream>
+
+#include <climits>
+#include <limits>
+
+
+#include <boost/mpl/logical.hpp>
+#include <boost/ratio.hpp>
+#include <boost/type_traits/common_type.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/type_traits/is_floating_point.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
+
+#include <boost/cstdint.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/detail/workaround.hpp>
+#include <boost/integer_traits.hpp>
+
+#if !defined(BOOST_NO_STATIC_ASSERT) || !defined(BOOST_CHRONO_USES_MPL_ASSERT)
+#define BOOST_CHRONO_A_DURATION_REPRESENTATION_CAN_NOT_BE_A_DURATION "A duration representation can not be a duration"
+#define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO "Second template parameter of duration must be a boost::ratio"
+#define BOOST_CHRONO_DURATION_PERIOD_MUST_BE_POSITIVE "duration period must be positive"
+#define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION "Second template parameter of time_point must be a boost::chrono::duration"
+#endif
+
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9 Time utilities [time] //
+// synopsis //
+// //
+//----------------------------------------------------------------------------//
+
+namespace boost {
+namespace chrono {
+
+ template <class Rep, class Period = ratio<1> >
+ class duration;
+
+ namespace detail
+ {
+ template <class T>
+ struct is_duration
+ : boost::false_type {};
+
+ template <class Rep, class Period>
+ struct is_duration<duration<Rep, Period> >
+ : boost::true_type {};
+ //template <class T>
+ // struct is_duration
+ // : is_duration<typename boost::remove_cv<T>::type> {};
+
+ template <class Duration, class Rep, bool = is_duration<Rep>::value>
+ struct duration_divide_result
+ {
+ };
+
+ template <class Duration, class Rep2,
+ bool = (
+ (boost::is_convertible<typename Duration::rep,
+ typename common_type<typename Duration::rep, Rep2>::type>::value)
+ && (boost::is_convertible<Rep2,
+ typename common_type<typename Duration::rep, Rep2>::type>::value)
+ )
+ >
+ struct duration_divide_imp
+ {
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_divide_imp<duration<Rep1, Period>, Rep2, true>
+ {
+ typedef duration<typename common_type<Rep1, Rep2>::type, Period> type;
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_divide_result<duration<Rep1, Period>, Rep2, false>
+ : duration_divide_imp<duration<Rep1, Period>, Rep2>
+ {
+ };
+
+///
+ template <class Rep, class Duration, bool = is_duration<Rep>::value>
+ struct duration_divide_result2
+ {
+ };
+
+ template <class Rep, class Duration,
+ bool = (
+ (boost::is_convertible<typename Duration::rep,
+ typename common_type<typename Duration::rep, Rep>::type>::value)
+ && (boost::is_convertible<Rep,
+ typename common_type<typename Duration::rep, Rep>::type>::value)
+ )
+ >
+ struct duration_divide_imp2
+ {
+ };
+
+ template <class Rep1, class Rep2, class Period >
+ struct duration_divide_imp2<Rep1, duration<Rep2, Period>, true>
+ {
+ //typedef typename common_type<Rep1, Rep2>::type type;
+ typedef double type;
+ };
+
+ template <class Rep1, class Rep2, class Period >
+ struct duration_divide_result2<Rep1, duration<Rep2, Period>, false>
+ : duration_divide_imp2<Rep1, duration<Rep2, Period> >
+ {
+ };
+
+///
+ template <class Duration, class Rep, bool = is_duration<Rep>::value>
+ struct duration_modulo_result
+ {
+ };
+
+ template <class Duration, class Rep2,
+ bool = (
+ //boost::is_convertible<typename Duration::rep,
+ //typename common_type<typename Duration::rep, Rep2>::type>::value
+ //&&
+ boost::is_convertible<Rep2,
+ typename common_type<typename Duration::rep, Rep2>::type>::value
+ )
+ >
+ struct duration_modulo_imp
+ {
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_modulo_imp<duration<Rep1, Period>, Rep2, true>
+ {
+ typedef duration<typename common_type<Rep1, Rep2>::type, Period> type;
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_modulo_result<duration<Rep1, Period>, Rep2, false>
+ : duration_modulo_imp<duration<Rep1, Period>, Rep2>
+ {
+ };
+
+ } // namespace detail
+} // namespace chrono
+
+
+// common_type trait specializations
+
+template <class Rep1, class Period1, class Rep2, class Period2>
+ struct common_type<chrono::duration<Rep1, Period1>,
+ chrono::duration<Rep2, Period2> >;
+
+
+namespace chrono {
+
+ // customization traits
+ template <class Rep> struct treat_as_floating_point;
+ template <class Rep> struct duration_values;
+
+ // duration arithmetic
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period, class Rep2>
+// typename boost::enable_if_c
+// <
+// boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>::value
+// && boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>::value,
+// duration<typename common_type<Rep1, Rep2>::type, Period>
+// >::type
+// operator*(const duration<Rep1, Period>& d, const Rep2& s);
+// template <class Rep1, class Period, class Rep2>
+// typename boost::enable_if_c
+// <
+// boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>::value
+// && boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>::value,
+// duration<typename common_type<Rep1, Rep2>::type, Period>
+// >::type
+// operator*(const Rep1& s, const duration<Rep2, Period>& d);
+
+// template <class Rep1, class Period, class Rep2>
+// typename boost::disable_if <detail::is_duration<Rep2>,
+// typename detail::duration_divide_result<duration<Rep1, Period>, Rep2>::type
+// >::type
+// operator/(const duration<Rep1, Period>& d, const Rep2& s);
+
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// typename common_type<Rep1, Rep2>::type
+// operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+ // duration comparisons
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+// template <class Rep1, class Period1, class Rep2, class Period2>
+// bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+ // duration_cast
+
+ //template <class ToDuration, class Rep, class Period>
+ // ToDuration duration_cast(const duration<Rep, Period>& d);
+
+ // convenience typedefs
+ typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed
+ typedef duration<boost::int_least64_t, micro> microseconds; // at least 55 bits needed
+ typedef duration<boost::int_least64_t, milli> milliseconds; // at least 45 bits needed
+ typedef duration<boost::int_least64_t> seconds; // at least 35 bits needed
+ typedef duration<boost::int_least32_t, ratio< 60> > minutes; // at least 29 bits needed
+ typedef duration<boost::int_least32_t, ratio<3600> > hours; // at least 23 bits needed
+
+//----------------------------------------------------------------------------//
+// duration helpers //
+//----------------------------------------------------------------------------//
+
+ namespace detail
+ {
+
+ // duration_cast
+
+ // duration_cast is the heart of this whole prototype. It can convert any
+ // duration to any other. It is also (implicitly) used in converting
+ // time_points. The conversion is always exact if possible. And it is
+ // always as efficient as hand written code. If different representations
+ // are involved, care is taken to never require implicit conversions.
+ // Instead static_cast is used explicitly for every required conversion.
+ // If there are a mixture of integral and floating point representations,
+ // the use of common_type ensures that the most logical "intermediate"
+ // representation is used.
+ template <class FromDuration, class ToDuration,
+ class Period = typename ratio_divide<typename FromDuration::period,
+ typename ToDuration::period>::type,
+ bool = Period::num == 1,
+ bool = Period::den == 1>
+ struct duration_cast;
+
+ // When the two periods are the same, all that is left to do is static_cast from
+ // the source representation to the target representation (which may be a no-op).
+ // This conversion is always exact as long as the static_cast from the source
+ // representation to the destination representation is exact.
+ template <class FromDuration, class ToDuration, class Period>
+ struct duration_cast<FromDuration, ToDuration, Period, true, true>
+ {
+ ToDuration operator()(const FromDuration& fd) const
+ {
+ return ToDuration(static_cast<typename ToDuration::rep>(fd.count()));
+ }
+ };
+
+ // When the numerator of FromPeriod / ToPeriod is 1, then all we need to do is
+ // divide by the denominator of FromPeriod / ToPeriod. The common_type of
+ // the two representations is used for the intermediate computation before
+ // static_cast'ing to the destination.
+ // This conversion is generally not exact because of the division (but could be
+ // if you get lucky on the run time value of fd.count()).
+ template <class FromDuration, class ToDuration, class Period>
+ struct duration_cast<FromDuration, ToDuration, Period, true, false>
+ {
+ ToDuration operator()(const FromDuration& fd) const
+ {
+ typedef typename common_type<
+ typename ToDuration::rep,
+ typename FromDuration::rep,
+ intmax_t>::type C;
+ return ToDuration(static_cast<typename ToDuration::rep>(
+ static_cast<C>(fd.count()) / static_cast<C>(Period::den)));
+ }
+ };
+
+ // When the denomenator of FromPeriod / ToPeriod is 1, then all we need to do is
+ // multiply by the numerator of FromPeriod / ToPeriod. The common_type of
+ // the two representations is used for the intermediate computation before
+ // static_cast'ing to the destination.
+ // This conversion is always exact as long as the static_cast's involved are exact.
+ template <class FromDuration, class ToDuration, class Period>
+ struct duration_cast<FromDuration, ToDuration, Period, false, true>
+ {
+ ToDuration operator()(const FromDuration& fd) const
+ {
+ typedef typename common_type<
+ typename ToDuration::rep,
+ typename FromDuration::rep,
+ intmax_t>::type C;
+ return ToDuration(static_cast<typename ToDuration::rep>(
+ static_cast<C>(fd.count()) * static_cast<C>(Period::num)));
+ }
+ };
+
+ // When neither the numerator or denominator of FromPeriod / ToPeriod is 1, then we need to
+ // multiply by the numerator and divide by the denominator of FromPeriod / ToPeriod. The
+ // common_type of the two representations is used for the intermediate computation before
+ // static_cast'ing to the destination.
+ // This conversion is generally not exact because of the division (but could be
+ // if you get lucky on the run time value of fd.count()).
+ template <class FromDuration, class ToDuration, class Period>
+ struct duration_cast<FromDuration, ToDuration, Period, false, false>
+ {
+ ToDuration operator()(const FromDuration& fd) const
+ {
+ typedef typename common_type<
+ typename ToDuration::rep,
+ typename FromDuration::rep,
+ intmax_t>::type C;
+ return ToDuration(static_cast<typename ToDuration::rep>(
+ static_cast<C>(fd.count()) * static_cast<C>(Period::num)
+ / static_cast<C>(Period::den)));
+ }
+ };
+
+ } // namespace detail
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9.2 Time-related traits [time.traits] //
+// //
+//----------------------------------------------------------------------------//
+//----------------------------------------------------------------------------//
+// 20.9.2.1 treat_as_floating_point [time.traits.is_fp] //
+// Probably should have been treat_as_floating_point. Editor notifed. //
+//----------------------------------------------------------------------------//
+
+ // Support bidirectional (non-exact) conversions for floating point rep types
+ // (or user defined rep types which specialize treat_as_floating_point).
+ template <class Rep>
+ struct treat_as_floating_point : boost::is_floating_point<Rep> {};
+
+//----------------------------------------------------------------------------//
+// 20.9.2.2 duration_values [time.traits.duration_values] //
+//----------------------------------------------------------------------------//
+
+ namespace detail {
+ template <class T, bool = is_arithmetic<T>::value>
+ struct chrono_numeric_limits {
+ static T lowest() throw() {return (std::numeric_limits<T>::min) ();}
+ };
+
+ template <class T>
+ struct chrono_numeric_limits<T,true> {
+ static T lowest() throw() {return (std::numeric_limits<T>::min) ();}
+ };
+
+ template <>
+ struct chrono_numeric_limits<float,true> {
+ static float lowest() throw() {return -(std::numeric_limits<float>::max) ();}
+ };
+
+ template <>
+ struct chrono_numeric_limits<double,true> {
+ static double lowest() throw() {return -(std::numeric_limits<double>::max) ();}
+ };
+
+ template <>
+ struct chrono_numeric_limits<long double,true> {
+ static long double lowest() throw() {return -(std::numeric_limits<long double>::max)();}
+ };
+
+ template <class T>
+ struct numeric_limits : chrono_numeric_limits<typename remove_cv<T>::type> {};
+
+ }
+ template <class Rep>
+ struct duration_values
+ {
+ static BOOST_CHRONO_CONSTEXPR Rep zero() {return Rep(0);}
+ static BOOST_CHRONO_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (std::numeric_limits<Rep>::max)();}
+
+ static BOOST_CHRONO_CONSTEXPR Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () {return detail::numeric_limits<Rep>::lowest();}
+ };
+
+} // namespace chrono
+
+//----------------------------------------------------------------------------//
+// 20.9.2.3 Specializations of common_type [time.traits.specializations] //
+//----------------------------------------------------------------------------//
+
+template <class Rep1, class Period1, class Rep2, class Period2>
+struct common_type<chrono::duration<Rep1, Period1>,
+ chrono::duration<Rep2, Period2> >
+{
+ typedef chrono::duration<typename common_type<Rep1, Rep2>::type,
+ typename boost::detail::ratio_gcd<Period1, Period2>::type> type;
+};
+
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9.3 Class template duration [time.duration] //
+// //
+//----------------------------------------------------------------------------//
+
+
+namespace chrono {
+
+ template <class Rep, class Period>
+ class duration
+ {
+ BOOST_CHRONO_STATIC_ASSERT(!boost::chrono::detail::is_duration<Rep>::value, BOOST_CHRONO_A_DURATION_REPRESENTATION_CAN_NOT_BE_A_DURATION, ());
+ BOOST_CHRONO_STATIC_ASSERT(boost::detail::is_ratio<Period>::value, BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO, ());
+ BOOST_CHRONO_STATIC_ASSERT(Period::num>0, BOOST_CHRONO_DURATION_PERIOD_MUST_BE_POSITIVE, ());
+ public:
+ typedef Rep rep;
+ typedef Period period;
+ private:
+ rep rep_;
+ public:
+
+ BOOST_CHRONO_CONSTEXPR duration() { } // = default;
+ template <class Rep2>
+ BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r,
+ typename boost::enable_if <
+ mpl::and_ <
+ boost::is_convertible<Rep2, rep>,
+ mpl::or_ <
+ treat_as_floating_point<rep>,
+ mpl::and_ <
+ mpl::not_ < treat_as_floating_point<rep> >,
+ mpl::not_ < treat_as_floating_point<Rep2> >
+ >
+ >
+ >
+ >::type* = 0)
+ : rep_(r) { }
+ ~duration() {} //= default;
+ duration(const duration& rhs) : rep_(rhs.rep_) {} // = default;
+ duration& operator=(const duration& rhs) // = default;
+ {
+ if (&rhs != this) rep_= rhs.rep_;
+ return *this;
+ }
+
+ // conversions
+ template <class Rep2, class Period2>
+ BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d,
+ typename boost::enable_if <
+ mpl::or_ <
+ treat_as_floating_point<rep>,
+ mpl::and_ <
+ mpl::bool_ < ratio_divide<Period2, period>::type::den == 1>,
+ mpl::not_ < treat_as_floating_point<Rep2> >
+ >
+ >
+ >::type* = 0)
+#ifdef __GNUC__
+ // GCC 4.2.4 refused to accept a definition at this point,
+ // yet both VC++ 9.0 SP1 and Intel ia32 11.0 accepted the definition
+ // without complaint. VC++ 9.0 SP1 refused to accept a later definition,
+ // although that was fine with GCC 4.2.4 and Intel ia32 11.0. Thus we
+ // have to support both approaches.
+ ;
+#else
+ : rep_(duration_cast<duration>(d).count()) {}
+#endif
+
+ // observer
+
+ BOOST_CHRONO_CONSTEXPR rep count() const {return rep_;}
+
+ // arithmetic
+
+ duration operator+() const {return *this;}
+ duration operator-() const {return duration(-rep_);}
+ duration& operator++() {++rep_; return *this;}
+ duration operator++(int) {return duration(rep_++);}
+ duration& operator--() {--rep_; return *this;}
+ duration operator--(int) {return duration(rep_--);}
+
+ duration& operator+=(const duration& d) {rep_ += d.count(); return *this;}
+ duration& operator-=(const duration& d) {rep_ -= d.count(); return *this;}
+
+ duration& operator*=(const rep& rhs) {rep_ *= rhs; return *this;}
+ duration& operator/=(const rep& rhs) {rep_ /= rhs; return *this;}
+ duration& operator%=(const rep& rhs) {rep_ %= rhs; return *this;}
+ duration& operator%=(const duration& rhs) {rep_ %= rhs.count(); return *this;};
+ // 20.9.3.4 duration special values [time.duration.special]
+
+ static BOOST_CHRONO_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
+ static BOOST_CHRONO_CONSTEXPR duration min BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::min)());}
+ static BOOST_CHRONO_CONSTEXPR duration max BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::max)());}
+ };
+
+//----------------------------------------------------------------------------//
+// 20.9.3.5 duration non-member arithmetic [time.duration.nonmember] //
+//----------------------------------------------------------------------------//
+
+ // Duration +
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ typename common_type<duration<Rep1, Period1>,
+ duration<Rep2, Period2> >::type result = lhs;
+ result += rhs;
+ return result;
+ }
+
+ // Duration -
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ typename common_type<duration<Rep1, Period1>,
+ duration<Rep2, Period2> >::type result = lhs;
+ result -= rhs;
+ return result;
+ }
+
+ // Duration *
+
+ template <class Rep1, class Period, class Rep2>
+ inline
+ typename boost::enable_if <
+ mpl::and_ <
+ boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>,
+ boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>
+ >,
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ >::type
+ operator*(const duration<Rep1, Period>& d, const Rep2& s)
+ {
+ typedef typename common_type<Rep1, Rep2>::type CR;
+ duration<CR, Period> r = d;
+ r *= static_cast<CR>(s);
+ return r;
+ }
+
+ template <class Rep1, class Period, class Rep2>
+ inline
+ typename boost::enable_if <
+ mpl::and_ <
+ boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>,
+ boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>
+ >,
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ >::type
+ operator*(const Rep1& s, const duration<Rep2, Period>& d)
+ {
+ return d * s;
+ }
+
+ // Duration /
+
+ template <class Rep1, class Period, class Rep2>
+ inline
+ typename boost::disable_if <boost::chrono::detail::is_duration<Rep2>,
+ typename boost::chrono::detail::duration_divide_result<duration<Rep1, Period>, Rep2>::type
+ >::type
+ operator/(const duration<Rep1, Period>& d, const Rep2& s)
+ {
+ typedef typename common_type<Rep1, Rep2>::type CR;
+ duration<CR, Period> r = d;
+ r /= static_cast<CR>(s);
+ return r;
+ }
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ typename common_type<Rep1, Rep2>::type
+ operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ typedef typename common_type<duration<Rep1, Period1>,
+ duration<Rep2, Period2> >::type CD;
+ return CD(lhs).count() / CD(rhs).count();
+ }
+
+ template <class Rep1, class Rep2, class Period>
+ inline
+ typename boost::disable_if <boost::chrono::detail::is_duration<Rep1>,
+ typename boost::chrono::detail::duration_divide_result2<Rep1, duration<Rep2, Period> >::type
+ >::type
+ operator/(const Rep1& s, const duration<Rep2, Period>& d)
+ {
+ typedef typename common_type<Rep1, Rep2>::type CR;
+ duration<CR, Period> r = d;
+ //return static_cast<CR>(r.count()) / static_cast<CR>(s);
+ return static_cast<CR>(s)/r.count();
+ }
+
+ // Duration %
+
+ template <class Rep1, class Period, class Rep2>
+ typename boost::disable_if <boost::chrono::detail::is_duration<Rep2>,
+ typename boost::chrono::detail::duration_modulo_result<duration<Rep1, Period>, Rep2>::type
+ >::type
+ operator%(const duration<Rep1, Period>& d, const Rep2& s) {
+ typedef typename common_type<Rep1, Rep2>::type CR;
+ duration<CR, Period> r = d;
+ r %= static_cast<CR>(s);
+ return r;
+ }
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs) {
+ typedef typename common_type<duration<Rep1, Period1>,
+ duration<Rep2, Period2> >::type CD;
+ CD r(lhs);
+ r%=CD(rhs);
+ return r;
+ }
+
+
+//----------------------------------------------------------------------------//
+// 20.9.3.6 duration comparisons [time.duration.comparisons] //
+//----------------------------------------------------------------------------//
+
+ namespace detail
+ {
+ template <class LhsDuration, class RhsDuration>
+ struct duration_eq
+ {
+ bool operator()(const LhsDuration& lhs, const RhsDuration& rhs)
+ {
+ typedef typename common_type<LhsDuration, RhsDuration>::type CD;
+ return CD(lhs).count() == CD(rhs).count();
+ }
+ };
+
+ template <class LhsDuration>
+ struct duration_eq<LhsDuration, LhsDuration>
+ {
+ bool operator()(const LhsDuration& lhs, const LhsDuration& rhs)
+ {return lhs.count() == rhs.count();}
+ };
+
+ template <class LhsDuration, class RhsDuration>
+ struct duration_lt
+ {
+ bool operator()(const LhsDuration& lhs, const RhsDuration& rhs)
+ {
+ typedef typename common_type<LhsDuration, RhsDuration>::type CD;
+ return CD(lhs).count() < CD(rhs).count();
+ }
+ };
+
+ template <class LhsDuration>
+ struct duration_lt<LhsDuration, LhsDuration>
+ {
+ bool operator()(const LhsDuration& lhs, const LhsDuration& rhs)
+ {return lhs.count() < rhs.count();}
+ };
+
+ } // namespace detail
+
+ // Duration ==
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return boost::chrono::detail::duration_eq<duration<Rep1, Period1>, duration<Rep2, Period2> >()(lhs, rhs);
+ }
+
+ // Duration !=
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ // Duration <
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return boost::chrono::detail::duration_lt<duration<Rep1, Period1>, duration<Rep2, Period2> >()(lhs, rhs);
+ }
+
+ // Duration >
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return rhs < lhs;
+ }
+
+ // Duration <=
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return !(rhs < lhs);
+ }
+
+ // Duration >=
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ inline
+ bool
+ operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
+ {
+ return !(lhs < rhs);
+ }
+
+//----------------------------------------------------------------------------//
+// 20.9.3.7 duration_cast [time.duration.cast] //
+//----------------------------------------------------------------------------//
+
+ // Compile-time select the most efficient algorithm for the conversion...
+ template <class ToDuration, class Rep, class Period>
+ inline
+ typename boost::enable_if <boost::chrono::detail::is_duration<ToDuration>, ToDuration>::type
+ duration_cast(const duration<Rep, Period>& fd)
+ {
+ return boost::chrono::detail::duration_cast<duration<Rep, Period>, ToDuration>()(fd);
+ }
+
+
+//----------------------------------------------------------------------------//
+// duration constructor implementation //
+// See comment in the class duration synopsis //
+//----------------------------------------------------------------------------//
+
+#ifdef __GNUC__
+ // see comment above in section 20.9.3 Class template duration [time.duration]
+ template <class Rep, class Period>
+ template <class Rep2, class Period2>
+ BOOST_CHRONO_CONSTEXPR duration<Rep, Period>::duration(const duration<Rep2, Period2>& d,
+ typename boost::enable_if <
+ mpl::or_ <
+ treat_as_floating_point<rep>,
+ mpl::and_ <
+ mpl::bool_ <ratio_divide<Period2, period>::type::den == 1>,
+ mpl::not_ <treat_as_floating_point<Rep2> >
+ >
+ >
+ >::type*)
+ : rep_(duration_cast<duration>(d).count()) {}
+#endif
+
+} // namespace chrono
+} // namespace boost
+
+#endif // BOOST_CHRONO_DURATION_HPP

Modified: sandbox/chrono/libs/ratio/example/si_physics.cpp
==============================================================================
--- sandbox/chrono/libs/ratio/example/si_physics.cpp (original)
+++ sandbox/chrono/libs/ratio/example/si_physics.cpp 2010-09-27 07:26:38 EDT (Mon, 27 Sep 2010)
@@ -7,7 +7,7 @@
 // See http://www.boost.org/LICENSE_1_0.txt
 
 #include <boost/ratio.hpp>
-#include <boost/chrono/duration.hpp>
+#include "duration.hpp"
 #include <iostream>
 
 namespace User1

Added: sandbox/chrono/libs/ratio/example/static_assert.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/ratio/example/static_assert.hpp 2010-09-27 07:26:38 EDT (Mon, 27 Sep 2010)
@@ -0,0 +1,30 @@
+// static_assert.hpp --------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_CHRONO_DETAIL_STATIC_ASSERT_HPP
+#define BOOST_CHRONO_DETAIL_STATIC_ASSERT_HPP
+
+#include "config.hpp"
+
+#ifndef BOOST_NO_STATIC_ASSERT
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
+#elif defined(BOOST_CHRONO_USES_STATIC_ASSERT)
+#include <boost/static_assert.hpp>
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
+#elif defined(BOOST_CHRONO_USES_MPL_ASSERT)
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) \
+ BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
+#else
+//~ #elif defined(BOOST_CHRONO_USES_ARRAY_ASSERT)
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_JOIN(boost_chrono_test_,__LINE__)[(CND)?1:-1]
+//~ #define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES)
+#endif
+
+#endif // BOOST_CHRONO_DETAIL_STATIC_ASSERT_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