Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70073 - in trunk/libs/chrono: doc test test/duration test/time_point
From: vicente.botet_at_[hidden]
Date: 2011-03-17 15:17:56


Author: viboes
Date: 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
New Revision: 70073
URL: http://svn.boost.org/trac/boost/changeset/70073

Log:
Chrono: #5322, #5323, time_point operators ++,--
Added:
   trunk/libs/chrono/test/time_point/arithmetic_ext_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/chrono/doc/chrono.qbk | 96 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/chrono/test/duration/constructor_pass.cpp | 5 +
   trunk/libs/chrono/test/rep.h | 36 ++++++++++++++
   trunk/libs/chrono/test/time_point/arithmetic_pass.cpp | 58 ++++++++++++++++++++++++
   4 files changed, 192 insertions(+), 3 deletions(-)

Modified: trunk/libs/chrono/doc/chrono.qbk
==============================================================================
--- trunk/libs/chrono/doc/chrono.qbk (original)
+++ trunk/libs/chrono/doc/chrono.qbk 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
@@ -9,7 +9,7 @@
 
 [library Boost.Chrono
     [quickbook 1.5]
- [version 1.0.0]
+ [version 1.1.0]
     [authors [Hinnant, Howard]]
     [authors [Dawes, Beman]]
     [authors [Botet Escriba, Vicente J.]]
@@ -2774,6 +2774,18 @@
 
         // arithmetic
 
+ #ifdef BOOST_CHRONO_EXTENSIONS
+ constexpr time_point operator+();
+ constexpr time_point operator-();
+ time_point& operator++();
+ time_point operator++(int);
+ time_point& operator--();
+ time_point operator--(int);
+
+ time_point& operator+=(const rep& d);
+ time_point& operator-=(const rep& d);
+ #endif
+
         time_point& operator+=(const duration& d);
         time_point& operator-=(const duration& d);
 
@@ -2818,6 +2830,74 @@
 __returns `d_`.
 
 [endsect]
+
+[section:operator_p Member Function `operator+() const`]
+
+ constexpr __time_point operator+() const;
+
+__returns `*this`.
+
+[endsect]
+[section:operator_m Member Function `operator-() const`]
+
+ constexpr __time_point operator-() const;
+
+__returns `__time_point(-d_)`.
+
+[endsect]
+[section:operator_pp Member Function `operator++()`]
+
+ __time_point& operator++();
+
+__effects `++d_`.
+
+__returns `*this`.
+
+[endsect]
+[section:operator_pp2 Member Function `operator++(int)`]
+
+ __time_point operator++(int);
+
+__returns `__time_point(d_++)`.
+
+[endsect]
+[section:operator_mm Member Function `operator--()`]
+
+ __time_point& operator--();
+
+__effects `--d_`.
+
+__returns `*this`.
+
+[endsect]
+[section:operator_mm2 Member Function `operator--(int)`]
+
+ __time_point operator--(int);
+
+__returns `__time_point(d_--)`.
+
+[endsect]
+
+[section:time_point_operator_per Member Function `operator+=`]
+
+ __time_point& operator+=(const rep& r);
+
+__effects `d_ += duration(r)`.
+
+__returns `*this`.
+
+[endsect]
+[section:time_point_operator_mer Member Function `operator-=`]
+
+ __time_point& operator-=(const rep& r);
+
+__effects `d_ -= duration(r)`
+
+__returns `*this`.
+
+[endsect]
+
+
 [section:time_point_operator_pe Member Function `operator+=`]
 
     time_point& operator+=(const duration& d);
@@ -3854,6 +3934,20 @@
 [section:history Appendix A: History]
 [/==================================]
 
+[section [*Version 1.1.0, Mars 17, 2011] ]
+
+[*New Features:]
+
+* [@http://svn.boost.org/trac/boost/ticket/???? #????] Added time_point unary operators +,-,++,-- and binary operators +=,-= with Rep al RHS.
+* [@http://svn.boost.org/trac/boost/ticket/5323 #5323] Add Associated type difference_type for chrono::time_point.
+
+[*Fixes:]
+
+* [@http://svn.boost.org/trac/boost/ticket/5322 #5322] Explicit default constructed chrono::durations are uninitialized
+
+
+[endsect] [/section [*Version 1.1.0, Mars 17, 2011] ]
+
 [section [*Version 1.0.0, January 6, 2011] ]
 
 * Moved chrono to trunk taking in account the review remarks.

Modified: trunk/libs/chrono/test/duration/constructor_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/duration/constructor_pass.cpp (original)
+++ trunk/libs/chrono/test/duration/constructor_pass.cpp 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
@@ -17,12 +17,15 @@
 
 
 #include <libs/chrono/test/rep.h>
+#include <iostream>
 
 template <class D>
 void
 check_default()
 {
- D d;
+ D d=D();
+ //std::cout << d.count() << std::endl;
+ //std::cout << typename D::rep() << std::endl;
     BOOST_TEST(d.count() == typename D::rep());
 }
 

Modified: trunk/libs/chrono/test/rep.h
==============================================================================
--- trunk/libs/chrono/test/rep.h (original)
+++ trunk/libs/chrono/test/rep.h 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
@@ -18,7 +18,7 @@
 {
 public:
     int data_;
- Rep() : data_(-1) {}
+ Rep() : data_() {}
     explicit Rep(int i) : data_(i) {}
 
     bool operator==(int i) const {return data_ == i;}
@@ -28,4 +28,38 @@
     Rep& operator/=(Rep x) {data_ /= x.data_; return *this;}
 };
 
+#if 0
+namespace std {
+
+ template <>
+ struct numeric_limits<Rep>
+ {
+ static BOOST_CHRONO_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return Rep((std::numeric_limits<int>::max)());
+ }
+
+ };
+} // namespace std
+
+namespace boost {
+namespace chrono {
+template <>
+struct duration_values<Rep>
+{
+ static BOOST_CHRONO_CONSTEXPR Rep zero() {return Rep(0);}
+ static BOOST_CHRONO_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return Rep((std::numeric_limits<int>::max)());
+ }
+
+ static BOOST_CHRONO_CONSTEXPR Rep min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ {
+ return Rep(detail::numeric_limits<Rep>::lowest());
+ }
+};
+
+} // namespace chrono
+} // namespace boost
+#endif
 #endif // REP_H

Added: trunk/libs/chrono/test/time_point/arithmetic_ext_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/test/time_point/arithmetic_ext_pass.cpp 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
@@ -0,0 +1,92 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Adaptation to Boost of the libcxx
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#define BOOST_CHRONO_EXTENSIONS
+#include <boost/chrono/chrono.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t += 2;
+ BOOST_TEST(t.time_since_epoch() == Duration(5));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t++;
+ BOOST_TEST(t.time_since_epoch() == Duration(4));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ ++t;
+ BOOST_TEST(t.time_since_epoch() == Duration(4));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t -= 2;
+ BOOST_TEST(t.time_since_epoch() == Duration(1));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t--;
+ BOOST_TEST(t.time_since_epoch() == Duration(2));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ --t;
+ BOOST_TEST(t.time_since_epoch() == Duration(2));
+ }
+#if 0
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
+ BOOST_TEST((t1 - t2) == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
+ t2 = Duration2(6) + t1;
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
+ }
+#endif
+
+ return boost::report_errors();
+}

Modified: trunk/libs/chrono/test/time_point/arithmetic_pass.cpp
==============================================================================
--- trunk/libs/chrono/test/time_point/arithmetic_pass.cpp (original)
+++ trunk/libs/chrono/test/time_point/arithmetic_pass.cpp 2011-03-17 15:17:49 EDT (Thu, 17 Mar 2011)
@@ -56,6 +56,64 @@
         t2 = Duration2(6) + t1;
         BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
     }
+#ifdef BOOST_CHRONO_EXTENSIONS
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t += 2;
+ BOOST_TEST(t.time_since_epoch() == Duration(5));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t++;
+ BOOST_TEST(t.time_since_epoch() == Duration(4));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ ++t;
+ BOOST_TEST(t.time_since_epoch() == Duration(4));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration;
+ boost::chrono::time_point<Clock, Duration> t(Duration(3));
+ t -= 2;
+ BOOST_TEST(t.time_since_epoch() == Duration(1));
+ }
+#if 0
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2(Duration2(5));
+ BOOST_TEST((t1 - t2) == Duration2(2995));
+ }
+ {
+ typedef boost::chrono::system_clock Clock;
+ typedef boost::chrono::milliseconds Duration1;
+ typedef boost::chrono::microseconds Duration2;
+ boost::chrono::time_point<Clock, Duration1> t1(Duration1(3));
+ boost::chrono::time_point<Clock, Duration2> t2 = t1 + Duration2(5);
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3005));
+ t2 = Duration2(6) + t1;
+ BOOST_TEST(t2.time_since_epoch() == Duration2(3006));
+ }
+#endif
+#endif
     
     return boost::report_errors();
 }


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