]>
Commit | Line | Data |
---|---|---|
41cd9d4d | 1 | // { dg-do compile { target c++20 } } |
03d5044b | 2 | |
a945c346 | 3 | // Copyright (C) 2020-2024 Free Software Foundation, Inc. |
03d5044b PP |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | // Class template day [time.cal.year] | |
21 | ||
22 | #include <chrono> | |
23 | ||
24 | constexpr void | |
25 | constexpr_year() | |
26 | { | |
27 | using namespace std::chrono; | |
28 | ||
29 | year dy{}; | |
30 | ++(++dy); | |
31 | dy++; | |
32 | --(--dy); | |
33 | dy--; | |
34 | dy += years{3}; | |
35 | dy -= years{3}; | |
36 | ||
37 | static_assert(++year{4} == year{5}); | |
38 | static_assert(year{4}++ == year{4}); | |
39 | static_assert(--year{4} == year{3}); | |
40 | static_assert(year{4}-- == year{4}); | |
41 | static_assert((year{4} += years{3}) == year{7}); | |
42 | static_assert((year{4} -= years{3}) == year{1}); | |
43 | ||
44 | static_assert(year{3} + years{7} == year{10}); | |
45 | static_assert(years{3} + year{7} == year{10}); | |
46 | static_assert(year{3} - years{7} == year{-4}); | |
47 | static_assert(year{10} - year{30} == years{-20}); | |
48 | ||
49 | const auto my = -dy; | |
50 | const auto py = +dy; | |
51 | ||
52 | static_assert((-year{1066} == year{-1066})); | |
53 | static_assert((-year{-332} == year{332})); | |
54 | static_assert((+year{1066} == year{1066})); | |
55 | static_assert((+year{-332} == year{-332})); | |
56 | ||
57 | year::min(); | |
58 | year::max(); | |
59 | ||
60 | static_assert(year{-12345}.ok()); | |
61 | static_assert(year{1}.ok()); | |
62 | static_assert(year{12}.ok()); | |
63 | static_assert(year{13}.ok()); | |
64 | ||
65 | static_assert(int{year{-42}} == -42); | |
66 | ||
67 | static_assert(!(year{0} == year{1})); | |
68 | static_assert( (year{0} != year{2})); | |
69 | static_assert( (year{0} < year{3})); | |
70 | static_assert(!(year{0} > year{4})); | |
71 | static_assert( (year{0} <= year{5})); | |
72 | static_assert(!(year{0} >= year{6})); | |
73 | ||
74 | static_assert(year{10} <=> year{11} == std::strong_ordering::less); | |
75 | static_assert(year{13} <=> year{13} == std::strong_ordering::equal); | |
76 | static_assert(year{15} <=> year{12} == std::strong_ordering::greater); | |
77 | ||
78 | static_assert( year{400}.is_leap()); | |
79 | static_assert( year{1984}.is_leap()); | |
80 | static_assert(!year{1}.is_leap()); | |
81 | static_assert( year{1600}.is_leap()); | |
82 | static_assert(!year{3000}.is_leap()); | |
83 | static_assert(!year{2019}.is_leap()); | |
84 | } |