From 7f4db7c80779ecbc57d1146654daf0acfe18de66 Mon Sep 17 00:00:00 2001 From: rus Date: Mon, 9 Nov 2009 20:58:24 +0000 Subject: merge from trunk git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/profile-stdlib@154052 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/include/std/chrono | 70 ++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'libstdc++-v3/include/std/chrono') diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index aa4888d9a9d..e80ec13c093 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -138,9 +138,20 @@ namespace std } }; + template + struct __is_duration + : std::false_type + { }; + + template + struct __is_duration> + : std::true_type + { }; + /// duration_cast template - inline _ToDuration + inline typename enable_if<__is_duration<_ToDuration>::value, + _ToDuration>::type duration_cast(const duration<_Rep, _Period>& __d) { typedef typename @@ -175,16 +186,6 @@ namespace std { return numeric_limits<_Rep>::min(); } }; - template - struct __is_duration - : std::false_type - { }; - - template - struct __is_duration> - : std::true_type - { }; - template struct __is_ratio : std::false_type @@ -210,24 +211,19 @@ namespace std // 20.8.3.1 construction / copy / destroy duration() = default; - template + template::value + && (treat_as_floating_point::value + || !treat_as_floating_point<_Rep2>::value)>::type> explicit duration(const _Rep2& __rep) - : __r(static_cast(__rep)) - { - static_assert(is_convertible<_Rep2,rep>::value - && (treat_as_floating_point::value - || !treat_as_floating_point<_Rep2>::value), - "cannot construct integral duration with floating point type"); - } + : __r(static_cast(__rep)) { } - template + template::value + || (ratio_divide<_Period2, period>::type::den == 1 + && !treat_as_floating_point<_Rep2>::value)>::type> duration(const duration<_Rep2, _Period2>& __d) - : __r(duration_cast(__d).count()) - { - static_assert(treat_as_floating_point::value == true - || ratio_divide<_Period2, period>::type::den == 1, - "the resulting duration is not exactly representable"); - } + : __r(duration_cast(__d).count()) { } ~duration() = default; duration(const duration&) = default; @@ -358,8 +354,17 @@ namespace std return __ct(__lhs) -= __rhs; } + template::type>::value> + struct __common_rep_type { }; + + template + struct __common_rep_type<_Rep1, _Rep2, true> + { typedef typename common_type<_Rep1, _Rep2>::type type; }; + template - inline duration::type, _Period> + inline duration::type, _Period> operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type __cr; @@ -367,12 +372,12 @@ namespace std } template - inline duration::type, _Period> - operator*(const _Rep2& __s, const duration<_Rep1, _Period>& __d) + inline duration::type, _Period> + operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { return __d * __s; } template - inline duration::value, _Rep2>::type>::type, _Period> operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { @@ -393,7 +398,7 @@ namespace std // DR 934. template - inline duration::value, _Rep2>::type>::type, _Period> operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { @@ -540,7 +545,8 @@ namespace std /// time_point_cast template - inline time_point<_Clock, _ToDuration> + inline typename enable_if<__is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration>>::type time_point_cast(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>( -- cgit v1.2.1