Re: [PATCH] libstdc++: Add more C++20 additions to

2020-08-25 Thread Jonathan Wakely via Gcc-patches

On 24/08/20 23:01 -0400, Patrick Palka via Libstdc++ wrote:

This patch adds the C++20 calendar types and their methods as defined in
[time.cal] (modulo the parsing/printing support).  This patch also
implements [time.hms] and [time.12], and a few more bits of
[time.clock].  The remaining C++20 additions to  from P0355 and
P1466 depend on [time.zone] and , so they will come later, as
will more optimized versions of some of the calendar algorithms.

The non-member operator overloads for the calendar types are defined as
namespace-scope functions in the standard, but here we instead define
each such operator overload as a hidden friend of the appropriate class.
This simplifies the implementation somewhat and lets us reap the
benefits of hidden friends for these routines.

The bulk of this work is based on a patch from Ed Smith-Rowland, which can
be found at the Git branch users/redi/heads/calendar.

Regression tested on x86_64-pc-linux-gnu, and also tested against the
testsuite for date.h of Howard Hinnant's 'date' library, i.e. the tests
at https://github.com/HowardHinnant/date/tree/master/test/date_test
(though some minor modifications to the tests are first needed to
account for the differences between the library API and the standard).


Looks good, please push (with the testsuite date fix mentioned on
IRC).

Thanks!




[PATCH] libstdc++: Add more C++20 additions to

2020-08-24 Thread Patrick Palka via Gcc-patches
This patch adds the C++20 calendar types and their methods as defined in
[time.cal] (modulo the parsing/printing support).  This patch also
implements [time.hms] and [time.12], and a few more bits of
[time.clock].  The remaining C++20 additions to  from P0355 and
P1466 depend on [time.zone] and , so they will come later, as
will more optimized versions of some of the calendar algorithms.

The non-member operator overloads for the calendar types are defined as
namespace-scope functions in the standard, but here we instead define
each such operator overload as a hidden friend of the appropriate class.
This simplifies the implementation somewhat and lets us reap the
benefits of hidden friends for these routines.

The bulk of this work is based on a patch from Ed Smith-Rowland, which can
be found at the Git branch users/redi/heads/calendar.

Regression tested on x86_64-pc-linux-gnu, and also tested against the
testsuite for date.h of Howard Hinnant's 'date' library, i.e. the tests
at https://github.com/HowardHinnant/date/tree/master/test/date_test
(though some minor modifications to the tests are first needed to
account for the differences between the library API and the standard).

Co-authored-by: Ed Smith-Rowland <3dw...@verizon.net>
Co-authored-by: Jonathan Wakely 

libstdc++-v3/ChangeLog:

* include/std/chrono (time_point::operator++)
(time_point::operator--): Define.
(utc_clock, tai_clock, gps_clock): Forward declare.
(utc_time, utc_seconds, tai_time, tai_seconds, gps_time)
(gps_seconds): Define.
(is_clock, is_clock, is_clock)
(is_clock_v, is_clock_v)
(is_clock_v): Define these specializations.
(leap_second_info): Define.
(day, month, year, weekday, weekday_indexed)
(weekday_last, month_day, month_day_last, month_weekday)
(month_weekday_last, year_month, year_month_day)
(year_month_day_last, year_month_weekday, year_month_weekday_last):
Declare and later define.
(last_spec, last, __detail::__days_per_month)
(__detail::__days_per_month, __detail::__last_day): Define.
(January, February, March, April, May, June, July, August)
(September, October, November, December, Sunday, Monday, Tuesday)
(Wednesday, Thursday, Friday, Saturday): Define.
(weekday::operator[]): Define out-of-line.
(year_month_day::_S_from_days, year_month_day::M_days_since_epoch):
Likewise.
(year_month_day::year_month_day, year_month_day::ok): Likewise.
(__detail::__pow10, hh_mm_ss): Define.
(literals::chrono_literals::operator""d)
(literals::chrono_literals::operator""y): Define.
(is_am, is_pm, make12, make24): Define.
* testsuite/20_util/time_point/4.cc: New test.
* testsuite/std/time/day/1.cc: New test.
* testsuite/std/time/hh_mm_ss/1.cc: New test.
* testsuite/std/time/is_am/1.cc: New test.
* testsuite/std/time/is_pm/1.cc: New test.
* testsuite/std/time/make12/1.cc: New test.
* testsuite/std/time/make24/1.cc: New test.
* testsuite/std/time/month/1.cc: New test.
* testsuite/std/time/month_day/1.cc: New test.
* testsuite/std/time/month_day_last/1.cc: New test.
* testsuite/std/time/month_weekday/1.cc: New test.
* testsuite/std/time/month_weekday_last/1.cc: New test.
* testsuite/std/time/weekday/1.cc: New test.
* testsuite/std/time/weekday_indexed/1.cc: New test.
* testsuite/std/time/weekday_last/1.cc: New test.
* testsuite/std/time/year/1.cc: New test.
* testsuite/std/time/year_month/1.cc: New test.
* testsuite/std/time/year_month_day/1.cc: New test.
* testsuite/std/time/year_month_day_last/1.cc: New test.
* testsuite/std/time/year_month_weekday/1.cc: New test.
* testsuite/std/time/year_month_weekday_last/1.cc: New test.
---
 libstdc++-v3/include/std/chrono   | 1907 +
 .../testsuite/20_util/time_point/4.cc |   42 +
 libstdc++-v3/testsuite/std/time/day/1.cc  |   67 +
 libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc |   63 +
 libstdc++-v3/testsuite/std/time/is_am/1.cc|   35 +
 libstdc++-v3/testsuite/std/time/is_pm/1.cc|   35 +
 libstdc++-v3/testsuite/std/time/make12/1.cc   |   36 +
 libstdc++-v3/testsuite/std/time/make24/1.cc   |   41 +
 libstdc++-v3/testsuite/std/time/month/1.cc|   75 +
 .../testsuite/std/time/month_day/1.cc |   73 +
 .../testsuite/std/time/month_day_last/1.cc|   65 +
 .../testsuite/std/time/month_weekday/1.cc |   48 +
 .../std/time/month_weekday_last/1.cc  |   48 +
 libstdc++-v3/testsuite/std/time/weekday/1.cc  |  102 +
 .../testsuite/std/time/weekday_indexed/1.cc   |   53 +
 .../testsuite/std/time/weekday_last/1.cc  |   48 +
 libstdc++-v3/testsuite/std/time/year/1.cc |   85 +
 .../testsuite/std/time/year_month/1.cc|   86 +