From patchwork Wed Nov 3 02:17:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Kosnik X-Patchwork-Id: 69940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BCB23B70CC for ; Wed, 3 Nov 2010 13:17:25 +1100 (EST) Received: (qmail 26894 invoked by alias); 3 Nov 2010 02:17:24 -0000 Received: (qmail 26877 invoked by uid 22791); 3 Nov 2010 02:17:21 -0000 X-SWARE-Spam-Status: No, hits=-5.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Nov 2010 02:17:15 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oA32HDo4030431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 2 Nov 2010 22:17:13 -0400 Received: from shotwell (ovpn-113-39.phx2.redhat.com [10.3.113.39]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oA32HC2M005311 for ; Tue, 2 Nov 2010 22:17:12 -0400 Date: Tue, 2 Nov 2010 19:17:11 -0700 From: Benjamin Kosnik To: gcc-patches@gcc.gnu.org Subject: [v3] add chrono typedefs Message-ID: <20101102191711.3e778143@shotwell> Mime-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Non-constexpr work to decompress some of these types. tested x86_64/linux -benjamin 2010-11-02 Benjamin Kosnik * include/std/chrono: Use typedefs. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust line numbers. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same. * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same. Index: include/std/chrono =================================================================== --- include/std/chrono (revision 166221) +++ include/std/chrono (working copy) @@ -60,7 +60,7 @@ template> struct duration; - template + template struct time_point; } @@ -69,71 +69,81 @@ struct common_type, chrono::duration<_Rep2, _Period2>> { - typedef chrono::duration::type, - ratio<__static_gcd<_Period1::num, _Period2::num>::value, - (_Period1::den / __static_gcd<_Period1::den, _Period2::den>::value) - * _Period2::den>> type; + private: + typedef __static_gcd<_Period1::num, _Period2::num> __gcd_num; + typedef __static_gcd<_Period1::den, _Period2::den> __gcd_den; + typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef ratio<__gcd_num::value, + (_Period1::den / __gcd_den::value) * _Period2::den> __r; + + public: + typedef chrono::duration<__cr, __r> type; }; // 20.8.2.3 specialization of common_type (for time_point) - template - struct common_type, - chrono::time_point<_Clock, _Duration2>> + template + struct common_type, + chrono::time_point<_Clock, _Dur2>> { - typedef chrono::time_point<_Clock, - typename common_type<_Duration1, _Duration2>::type> type; + private: + typedef typename common_type<_Dur1, _Dur2>::type __ct; + + public: + typedef chrono::time_point<_Clock, __ct> type; }; namespace chrono { // Primary template for duration_cast impl. - template struct __duration_cast_impl { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast< - typename _ToDuration::rep>(static_cast<_CR>(__d.count()) + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>(static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num) / static_cast<_CR>(_CF::den))); } }; - template - struct __duration_cast_impl<_ToDuration, _CF, _CR, true, true> + template + struct __duration_cast_impl<_ToDur, _CF, _CR, true, true> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration( - static_cast(__d.count())); + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>(__d.count())); } }; - template - struct __duration_cast_impl<_ToDuration, _CF, _CR, true, false> + template + struct __duration_cast_impl<_ToDur, _CF, _CR, true, false> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast( + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>( static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); } }; - template - struct __duration_cast_impl<_ToDuration, _CF, _CR, false, true> + template + struct __duration_cast_impl<_ToDur, _CF, _CR, false, true> { template - static constexpr _ToDuration + static constexpr _ToDur __cast(const duration<_Rep, _Period>& __d) { - return _ToDuration(static_cast( + typedef typename _ToDur::rep __to_rep; + return _ToDur(static_cast<__to_rep>( static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); } }; @@ -149,18 +159,20 @@ { }; /// duration_cast - template - inline constexpr typename enable_if<__is_duration<_ToDuration>::value, - _ToDuration>::type + template + inline constexpr typename enable_if<__is_duration<_ToDur>::value, + _ToDur>::type duration_cast(const duration<_Rep, _Period>& __d) { - typedef typename - ratio_divide<_Period, typename _ToDuration::period>::type __cf; - typedef typename - common_type::type __cr; - - return __duration_cast_impl<_ToDuration, __cf, __cr, - __cf::num == 1, __cf::den == 1>::__cast(__d); + typedef typename _ToDur::period __to_period; + typedef typename _ToDur::rep __to_rep; + typedef ratio_divide<_Period, __to_period> __r_div; + typedef typename __r_div::type __cf; + typedef typename common_type<__to_rep, _Rep, intmax_t>::type + __cr; + typedef __duration_cast_impl<_ToDur, __cf, __cr, + __cf::num == 1, __cf::den == 1> __dc; + return __dc::__cast(__d); } /// treat_as_floating_point @@ -200,8 +212,8 @@ template struct duration { - typedef _Rep rep; - typedef _Period period; + typedef _Rep rep; + typedef _Period period; static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); static_assert(__is_ratio<_Period>::value, @@ -336,8 +348,9 @@ operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) += __rhs; } @@ -348,8 +361,9 @@ operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) -= __rhs; } @@ -366,7 +380,7 @@ inline duration::type, _Period> operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) *= __s; } @@ -380,7 +394,7 @@ enable_if::value, _Rep2>::type>::type, _Period> operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) /= __s; } @@ -390,8 +404,9 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() / __ct(__rhs).count(); } @@ -401,7 +416,7 @@ enable_if::value, _Rep2>::type>::type, _Period> operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; + typedef typename common_type<_Rep1, _Rep2>::type __cr; return duration<__cr, _Period>(__d) %= __s; } @@ -412,8 +427,9 @@ operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs) %= __rhs; } @@ -424,8 +440,9 @@ operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() == __ct(__rhs).count(); } @@ -435,8 +452,9 @@ operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, - duration<_Rep2, _Period2>>::type __ct; + typedef duration<_Rep1, _Period1> __dur1; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<__dur1,__dur2>::type __ct; return __ct(__lhs).count() < __ct(__rhs).count(); } @@ -487,13 +505,13 @@ typedef duration> hours; /// time_point - template + template struct time_point { - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; + typedef _Clock clock; + typedef _Dur duration; + typedef typename duration::rep rep; + typedef typename duration::period period; constexpr time_point() : __d(duration::zero()) { } @@ -503,8 +521,8 @@ { } // conversions - template - constexpr time_point(const time_point& __t) + template + constexpr time_point(const time_point& __t) : __d(__t.time_since_epoch()) { } @@ -542,84 +560,84 @@ }; /// time_point_cast - template - inline constexpr typename enable_if<__is_duration<_ToDuration>::value, - time_point<_Clock, _ToDuration>>::type - time_point_cast(const time_point<_Clock, _Duration>& __t) + template + inline constexpr typename enable_if<__is_duration<_ToDur>::value, + time_point<_Clock, _ToDur>>::type + time_point_cast(const time_point<_Clock, _Dur>& __t) { - return time_point<_Clock, _ToDuration>( - duration_cast<_ToDuration>(__t.time_since_epoch())); + typedef time_point<_Clock, _ToDur> __time_point; + return __time_point(duration_cast<_ToDur>(__t.time_since_epoch())); } - template inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator+(const time_point<_Clock, _Duration1>& __lhs, + typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> + operator+(const time_point<_Clock, _Dur1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, - typename common_type<_Duration1, - duration<_Rep2, _Period2>>::type> __ct; - return __ct(__lhs) += __rhs; + typedef duration<_Rep2, _Period2> __dur2; + typedef typename common_type<_Dur1,__dur2>::type __ct; + typedef time_point<_Clock, __ct> __time_point; + return __time_point(__lhs) += __rhs; } template + typename _Clock, typename _Dur2> inline time_point<_Clock, - typename common_type, _Duration2>::type> + typename common_type, _Dur2>::type> operator+(const duration<_Rep1, _Period1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Dur2>& __rhs) { return __rhs + __lhs; } - template inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator-(const time_point<_Clock, _Duration1>& __lhs, + typename common_type<_Dur1, duration<_Rep2, _Period2>>::type> + operator-(const time_point<_Clock, _Dur1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return __lhs + (-__rhs); } - template - inline typename common_type<_Duration1, _Duration2>::type - operator-(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + template + inline typename common_type<_Dur1, _Dur2>::type + operator-(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator==(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator==(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator!=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator!=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__lhs == __rhs); } - template + template inline constexpr bool - operator<(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator<(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } - template + template inline constexpr bool - operator<=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator<=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__rhs < __lhs); } - template + template inline constexpr bool - operator>(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator>(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return __rhs < __lhs; } - template + template inline constexpr bool - operator>=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator>=(const time_point<_Clock, _Dur1>& __lhs, + const time_point<_Clock, _Dur2>& __rhs) { return !(__lhs < __rhs); } /// system_clock @@ -650,16 +668,16 @@ static std::time_t to_time_t(const time_point& __t) { - return std::time_t( - duration_cast(__t.time_since_epoch()).count()); + return std::time_t(duration_cast + (__t.time_since_epoch()).count()); } static time_point from_time_t(std::time_t __t) { - return time_point_cast( - chrono::time_point( - chrono::seconds(__t))); + typedef chrono::time_point __from; + return time_point_cast + (__from(chrono::seconds(__t))); } }; Index: testsuite/20_util/duration/requirements/typedefs_neg1.cc =================================================================== --- testsuite/20_util/duration/requirements/typedefs_neg1.cc (revision 166221) +++ testsuite/20_util/duration/requirements/typedefs_neg1.cc (working copy) @@ -31,5 +31,5 @@ test_type d; } -// { dg-error "rep cannot be a duration" "" { target *-*-* } 206 } +// { dg-error "rep cannot be a duration" "" { target *-*-* } 218 } // { dg-error "instantiated from here" "" { target *-*-* } 31 } Index: testsuite/20_util/duration/requirements/typedefs_neg2.cc =================================================================== --- testsuite/20_util/duration/requirements/typedefs_neg2.cc (revision 166221) +++ testsuite/20_util/duration/requirements/typedefs_neg2.cc (working copy) @@ -32,6 +32,6 @@ test_type d; } -// { dg-error "must be a specialization of ratio" "" { target *-*-* } 207 } +// { dg-error "must be a specialization of ratio" "" { target *-*-* } 219 } // { dg-error "instantiated from here" "" { target *-*-* } 32 } // { dg-excess-errors "In instantiation of" } Index: testsuite/20_util/duration/requirements/typedefs_neg3.cc =================================================================== --- testsuite/20_util/duration/requirements/typedefs_neg3.cc (revision 166221) +++ testsuite/20_util/duration/requirements/typedefs_neg3.cc (working copy) @@ -33,5 +33,5 @@ test_type d; } -// { dg-error "period must be positive" "" { target *-*-* } 209 } +// { dg-error "period must be positive" "" { target *-*-* } 221 } // { dg-error "instantiated from here" "" { target *-*-* } 33 } Index: testsuite/20_util/ratio/cons/cons_overflow_neg.cc =================================================================== --- testsuite/20_util/ratio/cons/cons_overflow_neg.cc (revision 166221) +++ testsuite/20_util/ratio/cons/cons_overflow_neg.cc (working copy) @@ -51,6 +51,7 @@ // { dg-error "instantiated from here" "" { target *-*-* } 46 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 153 } // { dg-error "out of range" "" { target *-*-* } 154 } -// { dg-error "constant expression" "" { target *-*-* } 59 } +// { dg-error "non-constant expression" "" { target *-*-* } 59 } +// { dg-error "is not a constant expression" "" { target *-*-* } 59 } // { dg-error "not a member" "" { target *-*-* } 162 } // { dg-error "not a valid template argument" "" { target *-*-* } 164 }