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 <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 using year = std::chrono::year;
23 using month = std::chrono::month;
24 using weekday = std::chrono::weekday;
25 using weekday_last = std::chrono::weekday_last;
26 using year_month_weekday_last = std::chrono::year_month_weekday_last;
27 using months = std::chrono::months;
28
29 constexpr bool test() {
30 constexpr weekday Tuesday = std::chrono::Tuesday;
31
32 for (unsigned i = 0; i <= 10; ++i) {
33 year y{1234};
34 year_month_weekday_last ymwdl(y, month{i}, weekday_last{Tuesday});
35
36 assert(static_cast<unsigned>((ymwdl += months{2}).month()) == i + 2);
37 assert(ymwdl.year() == y);
38 assert(ymwdl.weekday() == Tuesday);
39
40 assert(static_cast<unsigned>((ymwdl).month()) == i + 2);
41 assert(ymwdl.year() == y);
42 assert(ymwdl.weekday() == Tuesday);
43
44 assert(static_cast<unsigned>((ymwdl -= months{1}).month()) == i + 1);
45 assert(ymwdl.year() == y);
46 assert(ymwdl.weekday() == Tuesday);
47
48 assert(static_cast<unsigned>((ymwdl).month()) == i + 1);
49 assert(ymwdl.year() == y);
50 assert(ymwdl.weekday() == Tuesday);
51 }
52
53 { // Test year wrapping
54 year_month_weekday_last ymwdl{year{2020}, month{4}, weekday_last{Tuesday}};
55
56 ymwdl += months{12};
57 assert((ymwdl == year_month_weekday_last{year{2021}, month{4}, weekday_last{Tuesday}}));
58
59 ymwdl -= months{12};
60 assert((ymwdl == year_month_weekday_last{year{2020}, month{4}, weekday_last{Tuesday}}));
61 }
62 return true;
63 }
64
65 int main(int, char**) {
66 ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() += std::declval<months>());
67 ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() -= std::declval<months>());
68
69 ASSERT_SAME_TYPE(
70 year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() += std::declval<months>()));
71 ASSERT_SAME_TYPE(
72 year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() -= std::declval<months>()));
73
74 test();
75 static_assert(test());
76
77 return 0;
78 }