diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2009-07-21 14:48:47 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2009-07-21 14:48:47 +0000 |
commit | 513c5a5bd9e856bd90c8d6cc6909e007b533ca8f (patch) | |
tree | 91f3841f0eaf58dd0cbf3086bd3fba2668cce630 /libstdc++-v3/include/std | |
parent | a1516d083635329af0ad21c5f2e3daf3bd92219d (diff) | |
download | gcc-513c5a5bd9e856bd90c8d6cc6909e007b533ca8f.zip gcc-513c5a5bd9e856bd90c8d6cc6909e007b533ca8f.tar.gz gcc-513c5a5bd9e856bd90c8d6cc6909e007b533ca8f.tar.bz2 |
chrono (duration<>::operator%=, operator%): Add, per DR 934.
2009-07-21 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/chrono (duration<>::operator%=, operator%):
Add, per DR 934.
* testsuite/20_util/duration/arithmetic/dr934-1.cc: New.
* testsuite/20_util/duration/arithmetic/dr934-2.cc: Likewise.
* include/std/chrono (operator/): Simplify implementation.
From-SVN: r149856
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/chrono | 106 |
1 files changed, 64 insertions, 42 deletions
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index d18f277..aa4888d 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -154,7 +154,7 @@ namespace std /// treat_as_floating_point template<typename _Rep> - struct treat_as_floating_point + struct treat_as_floating_point : is_floating_point<_Rep> { }; @@ -211,7 +211,7 @@ namespace std duration() = default; template<typename _Rep2> - explicit duration(_Rep2 const& __rep) + explicit duration(const _Rep2& __rep) : __r(static_cast<rep>(__rep)) { static_assert(is_convertible<_Rep2,rep>::value @@ -244,29 +244,29 @@ namespace std { return *this; } duration - operator-() const + operator-() const { return duration(-__r); } duration& - operator++() + operator++() { ++__r; return *this; } duration - operator++(int) + operator++(int) { return duration(__r++); } duration& - operator--() - { + operator--() + { --__r; return *this; } duration - operator--(int) + operator--(int) { return duration(__r--); } duration& @@ -292,11 +292,30 @@ namespace std duration& operator/=(const rep& __rhs) - { + { __r /= __rhs; return *this; } + // DR 934. + template<typename _Rep2 = rep> + typename enable_if<!treat_as_floating_point<_Rep2>::value, + duration&>::type + operator%=(const rep& __rhs) + { + __r %= __rhs; + return *this; + } + + template<typename _Rep2 = rep> + typename enable_if<!treat_as_floating_point<_Rep2>::value, + duration&>::type + operator%=(const duration& __d) + { + __r %= __d.count(); + return *this; + } + // 20.8.3.4 special values // TODO: These should be constexprs. static const duration @@ -310,8 +329,8 @@ namespace std static const duration max() { return duration(duration_values<rep>::max()); } - - private: + + private: rep __r; }; @@ -351,46 +370,49 @@ namespace std inline duration<typename common_type<_Rep1, _Rep2>::type, _Period> operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d) { return __d * __s; } - - template<typename _Tp, typename _Up, typename _Ep = void> - struct __division_impl; - + template<typename _Rep1, typename _Period, typename _Rep2> - struct __division_impl<duration<_Rep1, _Period>, _Rep2, - typename enable_if<!__is_duration<_Rep2>::value>::type> + inline duration<typename common_type<_Rep1, typename + enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period> + operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; - typedef - duration<typename common_type<_Rep1, _Rep2>::type, _Period> __rt; - - static __rt - __divide(const duration<_Rep1, _Period>& __d, const _Rep2& __s) - { return duration<__cr, _Period>(__d) /= __s; } - }; + typedef typename common_type<_Rep1, _Rep2>::type __cr; + return duration<__cr, _Period>(__d) /= __s; + } - template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - struct __division_impl<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>> + template<typename _Rep1, typename _Period1, + typename _Rep2, typename _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 __ct; - typedef typename common_type<_Rep1, _Rep2>::type __rt; + return __ct(__lhs).count() / __ct(__rhs).count(); + } - static __rt - __divide(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) - { return __ct(__lhs).count() / __ct(__rhs).count(); } - }; - - template<typename _Rep, typename _Period, typename _Up> - inline typename __division_impl<duration<_Rep, _Period>, _Up>::__rt - operator/(const duration<_Rep, _Period>& __d, const _Up& __u) + // DR 934. + template<typename _Rep1, typename _Period, typename _Rep2> + inline duration<typename common_type<_Rep1, typename + enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period> + operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - return - __division_impl<duration<_Rep, _Period>, _Up>::__divide(__d, __u); + typedef typename common_type<_Rep1, _Rep2>::type __cr; + return duration<__cr, _Period>(__d) %= __s; } - + + template<typename _Rep1, typename _Period1, + typename _Rep2, typename _Period2> + inline 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 __ct; + return __ct(__lhs) %= __rhs; + } + // comparisons template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> |