Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_month.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <chrono>
11 // class year_month_weekday_last;
12
13 // constexpr year_month_weekday_last& operator+=(const months& m) noexcept;
14 // constexpr year_month_weekday_last& operator-=(const months& m) noexcept;
15
16 #include <chrono>
17 #include <cassert>
18 #include <type_traits>
19 #include <utility>
20
21 #include "test_macros.h"
22
23 using year = std::chrono::year;
24 using month = std::chrono::month;
25 using weekday = std::chrono::weekday;
26 using weekday_last = std::chrono::weekday_last;
27 using year_month_weekday_last = std::chrono::year_month_weekday_last;
28 using months = std::chrono::months;
29
30 constexpr bool test() {
31 constexpr weekday Tuesday = std::chrono::Tuesday;
32
33 for (unsigned i = 0; i <= 10; ++i) {
34 year y{1234};
35 year_month_weekday_last ymwdl(y, month{i}, weekday_last{Tuesday});
36
37 assert(static_cast<unsigned>((ymwdl += months{2}).month()) == i + 2);
38 assert(ymwdl.year() == y);
39 assert(ymwdl.weekday() == Tuesday);
40
41 assert(static_cast<unsigned>((ymwdl).month()) == i + 2);
42 assert(ymwdl.year() == y);
43 assert(ymwdl.weekday() == Tuesday);
44
45 assert(static_cast<unsigned>((ymwdl -= months{1}).month()) == i + 1);
46 assert(ymwdl.year() == y);
47 assert(ymwdl.weekday() == Tuesday);
48
49 assert(static_cast<unsigned>((ymwdl).month()) == i + 1);
50 assert(ymwdl.year() == y);
51 assert(ymwdl.weekday() == Tuesday);
52 }
53
54 { // Test year wrapping
55 year_month_weekday_last ymwdl{year{2020}, month{4}, weekday_last{Tuesday}};
56
57 ymwdl += months{12};
58 assert((ymwdl == year_month_weekday_last{year{2021}, month{4}, weekday_last{Tuesday}}));
59
60 ymwdl -= months{12};
61 assert((ymwdl == year_month_weekday_last{year{2020}, month{4}, weekday_last{Tuesday}}));
62 }
63 return true;
64 }
65
66 int main(int, char**) {
67 ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() += std::declval<months>());
68 ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() -= std::declval<months>());
69
70 ASSERT_SAME_TYPE(
71 year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() += std::declval<months>()));
72 ASSERT_SAME_TYPE(
73 year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() -= std::declval<months>()));
74
75 test();
76 static_assert(test());
77
78 return 0;
79 }