Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ymwd/time.cal.ymwd.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;
12
13 // constexpr year_month_weekday& operator+=(const months& m) noexcept;
14 // constexpr year_month_weekday& 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_indexed = std::chrono::weekday_indexed;
26 using year_month_weekday = std::chrono::year_month_weekday;
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 ymwd(y, month{i}, weekday_indexed{Tuesday, 2});
35
36 assert(static_cast<unsigned>((ymwd += months{2}).month()) == i + 2);
37 assert(ymwd.year() == y);
38 assert(ymwd.weekday() == Tuesday);
39 assert(ymwd.index() == 2);
40
41 assert(static_cast<unsigned>((ymwd).month()) == i + 2);
42 assert(ymwd.year() == y);
43 assert(ymwd.weekday() == Tuesday);
44 assert(ymwd.index() == 2);
45
46 assert(static_cast<unsigned>((ymwd -= months{1}).month()) == i + 1);
47 assert(ymwd.year() == y);
48 assert(ymwd.weekday() == Tuesday);
49 assert(ymwd.index() == 2);
50
51 assert(static_cast<unsigned>((ymwd).month()) == i + 1);
52 assert(ymwd.year() == y);
53 assert(ymwd.weekday() == Tuesday);
54 assert(ymwd.index() == 2);
55 }
56
57 { // Test year wrapping
58 year_month_weekday ymwd{year{2020}, month{4}, weekday_indexed{Tuesday, 2}};
59
60 ymwd += months{12};
61 assert((ymwd == year_month_weekday{year{2021}, month{4}, weekday_indexed{Tuesday, 2}}));
62
63 ymwd -= months{12};
64 assert((ymwd == year_month_weekday{year{2020}, month{4}, weekday_indexed{Tuesday, 2}}));
65 }
66
67 return true;
68 }
69
70 int main(int, char**) {
71 ASSERT_NOEXCEPT(std::declval<year_month_weekday&>() += std::declval<months>());
72 ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval<year_month_weekday&>() += std::declval<months>()));
73
74 ASSERT_NOEXCEPT(std::declval<year_month_weekday&>() -= std::declval<months>());
75 ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval<year_month_weekday&>() -= std::declval<months>()));
76
77 test();
78 static_assert(test());
79
80 return 0;
81 }