Debian Codegraph @

libstdc++-v3/testsuite/std/time/day/1.cc

raw
1 // { dg-do compile { target c++20 } }
2
3 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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.day]
21
22 #include <chrono>
23
24 constexpr void
25 constexpr_day()
26 {
27 using namespace std::chrono;
28
29 day dd{};
30 ++(++dd);
31 dd++;
32 --(--dd);
33 dd--;
34 dd += days{3};
35 dd -= days{3};
36
37 static_assert(day{1} + days{2} == day{3});
38 static_assert(days{2} + day{1} == day{3});
39 static_assert(day{3} - day{1} == days{2});
40 static_assert(day{3} - days{1} == day{2});
41
42 static_assert(++day{4} == day{5});
43 static_assert(day{4}++ == day{4});
44 static_assert(--day{4} == day{3});
45 static_assert(day{4}-- == day{4});
46 static_assert((day{4} += days{3}) == day{7});
47 static_assert((day{4} -= days{3}) == day{1});
48
49 static_assert(!day{}.ok());
50 static_assert(day{1}.ok());
51 static_assert(day{31}.ok());
52 static_assert(!day{32}.ok());
53
54 static_assert(unsigned{day{7}} == 7);
55
56 static_assert(!(day{0} == day{1}));
57 static_assert( (day{0} != day{2}));
58 static_assert( (day{0} < day{3}));
59 static_assert(!(day{0} > day{4}));
60 static_assert( (day{0} <= day{5}));
61 static_assert(!(day{0} >= day{6}));
62
63 static_assert(day{0} <=> day{1} == std::strong_ordering::less);
64 static_assert(day{3} <=> day{3} == std::strong_ordering::equal);
65 static_assert(day{5} <=> day{2} == std::strong_ordering::greater);
66 }