]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/time/year/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / time / year / 1.cc
CommitLineData
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.year]
22
23#include <chrono>
24
25constexpr void
26constexpr_year()
27{
28 using namespace std::chrono;
29
30 year dy{};
31 ++(++dy);
32 dy++;
33 --(--dy);
34 dy--;
35 dy += years{3};
36 dy -= years{3};
37
38 static_assert(++year{4} == year{5});
39 static_assert(year{4}++ == year{4});
40 static_assert(--year{4} == year{3});
41 static_assert(year{4}-- == year{4});
42 static_assert((year{4} += years{3}) == year{7});
43 static_assert((year{4} -= years{3}) == year{1});
44
45 static_assert(year{3} + years{7} == year{10});
46 static_assert(years{3} + year{7} == year{10});
47 static_assert(year{3} - years{7} == year{-4});
48 static_assert(year{10} - year{30} == years{-20});
49
50 const auto my = -dy;
51 const auto py = +dy;
52
53 static_assert((-year{1066} == year{-1066}));
54 static_assert((-year{-332} == year{332}));
55 static_assert((+year{1066} == year{1066}));
56 static_assert((+year{-332} == year{-332}));
57
58 year::min();
59 year::max();
60
61 static_assert(year{-12345}.ok());
62 static_assert(year{1}.ok());
63 static_assert(year{12}.ok());
64 static_assert(year{13}.ok());
65
66 static_assert(int{year{-42}} == -42);
67
68 static_assert(!(year{0} == year{1}));
69 static_assert( (year{0} != year{2}));
70 static_assert( (year{0} < year{3}));
71 static_assert(!(year{0} > year{4}));
72 static_assert( (year{0} <= year{5}));
73 static_assert(!(year{0} >= year{6}));
74
75 static_assert(year{10} <=> year{11} == std::strong_ordering::less);
76 static_assert(year{13} <=> year{13} == std::strong_ordering::equal);
77 static_assert(year{15} <=> year{12} == std::strong_ordering::greater);
78
79 static_assert( year{400}.is_leap());
80 static_assert( year{1984}.is_leap());
81 static_assert(!year{1}.is_leap());
82 static_assert( year{1600}.is_leap());
83 static_assert(!year{3000}.is_leap());
84 static_assert(!year{2019}.is_leap());
85}