03d5044b31
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 <chrono> from P0355 and P1466 depend on [time.zone] and <format>, so they will come later, as will more optimized versions of some of the algorithms added here. The non-member operator overloads for the calendar types are defined as namespace-scope functions in the standard, but here we instead define these operator overloads as hidden friends. This simplifies the implementation somewhat and lets us reap the benefits of hidden friends for these overloads. 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. Co-authored-by: Ed Smith-Rowland <3dw4rd@verizon.net> Co-authored-by: Jonathan Wakely <jwakely@redhat.com> 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<utc_clock>, is_clock<tai_clock>, is_clock<gps_clock>) (is_clock_v<utc_clock>, is_clock_v<tai_clock>) (is_clock_v<gps_clock>): 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.
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
// { dg-options "-std=gnu++2a" }
|
|
// { dg-do compile { target c++2a } }
|
|
|
|
// Copyright (C) 2020 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING3. If not see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
// Class template day [time.cal.weekday_last]
|
|
|
|
#include <chrono>
|
|
|
|
constexpr void
|
|
constexpr_weekday_last()
|
|
{
|
|
using namespace std::chrono;
|
|
|
|
constexpr auto wdl0 = Sunday[last];
|
|
static_assert(wdl0.weekday() == Sunday);
|
|
|
|
constexpr auto wdl1 = weekday{3}[2];
|
|
static_assert(wdl1.weekday() == weekday{3});
|
|
static_assert(wdl1.index() == 2);
|
|
constexpr auto wdll = weekday{3}[last];
|
|
static_assert(wdll.weekday() == weekday{3});
|
|
|
|
static_assert(!weekday_last{weekday{127}}.ok());
|
|
static_assert(weekday_last{weekday{0}}.ok());
|
|
static_assert(weekday_last{weekday{6}}.ok());
|
|
static_assert(weekday_last{weekday{7}}.ok()); // Weekday wraps 7 to 0.
|
|
static_assert(!weekday_last{weekday{8}}.ok());
|
|
|
|
static_assert( (weekday_last{weekday{7}} == weekday_last{weekday{0}}));
|
|
static_assert(!(weekday_last{weekday{0}} == weekday_last{weekday{1}}));
|
|
static_assert( (weekday_last{weekday{0}} != weekday_last{weekday{2}}));
|
|
}
|