]>
Commit | Line | Data |
---|---|---|
03d5044b PP |
1 | // { dg-options "-std=gnu++2a" } |
2 | // { dg-do compile { target c++2a } } | |
3 | ||
99dee823 | 4 | // Copyright (C) 2020-2021 Free Software Foundation, Inc. |
03d5044b PP |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | // Class template day [time.cal.weekday] | |
22 | ||
23 | #include <chrono> | |
24 | ||
25 | constexpr void | |
26 | constexpr_weekday() | |
27 | { | |
28 | using namespace std::chrono; | |
29 | ||
30 | weekday dwd{}; | |
31 | ++dwd; | |
32 | dwd++; | |
33 | --dwd; | |
34 | dwd--; | |
35 | dwd += days{3}; | |
36 | dwd -= days{3}; | |
37 | ||
38 | static_assert(weekday{3}[2].weekday() == weekday{3}); | |
39 | static_assert(weekday{3}[last].weekday() == weekday{3}); | |
40 | ||
41 | static_assert(weekday{sys_days{1900y/January/1}} == Monday); | |
42 | static_assert(weekday{sys_days{1970y/January/1}} == Thursday); | |
43 | static_assert(weekday{sys_days{2020y/August/21}} == Friday); | |
44 | ||
45 | static_assert(weekday{local_days{1900y/January/1}} == Monday); | |
46 | static_assert(weekday{local_days{1970y/January/1}} == Thursday); | |
47 | static_assert(weekday{local_days{2020y/August/21}} == Friday); | |
48 | ||
49 | static_assert(++weekday{3} == weekday{4}); | |
50 | static_assert(weekday{3}++ == weekday{3}); | |
51 | static_assert(--weekday{3} == weekday{2}); | |
52 | static_assert(weekday{3}-- == weekday{3}); | |
53 | static_assert((weekday{3} += days{3}) == weekday{6}); | |
54 | static_assert((weekday{3} -= days{3}) == weekday{0}); | |
55 | ||
56 | static_assert(Monday + days{7000} == Monday); | |
57 | static_assert(Monday + days{-7000} == Monday); | |
58 | static_assert(days{7001} + Monday == Tuesday); | |
59 | static_assert(days{-7001} + Monday == Sunday); | |
60 | static_assert(Monday - days{7000} == Monday); | |
61 | static_assert(Monday - days{-7000} == Monday); | |
62 | static_assert(Monday - days{7001} == Sunday); | |
63 | ||
64 | static_assert([] { | |
65 | constexpr unsigned diff_tbl[7][7] | |
66 | = { { 0, 6, 5, 4, 3, 2, 1}, | |
67 | { 1, 0, 6, 5, 4, 3, 2}, | |
68 | { 2, 1, 0, 6, 5, 4, 3}, | |
69 | { 3, 2, 1, 0, 6, 5, 4}, | |
70 | { 4, 3, 2, 1, 0, 6, 5}, | |
71 | { 5, 4, 3, 2, 1, 0, 6}, | |
72 | { 6, 5, 4, 3, 2, 1, 0} }; | |
73 | for (unsigned x = 0; x < 7; x++) | |
74 | for (unsigned y = 0; y < 7; y++) | |
75 | { | |
76 | if (weekday{x} - weekday{y} != days{diff_tbl[x][y]}) | |
77 | return false; | |
78 | if (weekday{x} - days{diff_tbl[x][y]} != weekday{y}) | |
79 | return false; | |
80 | if (weekday{x} != weekday{y} + days{diff_tbl[x][y]}) | |
81 | return false; | |
82 | if (weekday{x} != days{diff_tbl[x][y]} + weekday{y}) | |
83 | return false; | |
84 | } | |
85 | return true; | |
86 | }()); | |
87 | ||
88 | static_assert(Sunday.c_encoding() == 0); | |
89 | static_assert(Sunday.iso_encoding() == 7); | |
90 | static_assert(Monday.c_encoding() == 1); | |
91 | static_assert(Monday.iso_encoding() == 1); | |
92 | ||
93 | static_assert(!weekday{127}.ok()); | |
94 | static_assert(weekday{0}.ok()); | |
95 | static_assert(weekday{6}.ok()); | |
96 | static_assert(weekday{7}.ok()); // Ctor wraps 7 to 0. | |
97 | static_assert(!weekday{8}.ok()); | |
98 | ||
99 | static_assert(weekday{7} == weekday{0}); | |
100 | static_assert(!(weekday{0} == weekday{1})); | |
101 | static_assert( (weekday{0} != weekday{2})); | |
102 | } |