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 years& d) noexcept;
14// constexpr year_month_weekday& operator-=(const years& d) noexcept;
15
16#include <chrono>
17#include <cassert>
18#include <type_traits>
19#include <utility>
20
21#include "test_macros.h"
22
23using year = std::chrono::year;
24using month = std::chrono::month;
25using weekday = std::chrono::weekday;
26using weekday_indexed = std::chrono::weekday_indexed;
27using year_month_weekday = std::chrono::year_month_weekday;
28using years = std::chrono::years;
29
30constexpr bool test() {
31 constexpr weekday Tuesday = std::chrono::Tuesday;
32 constexpr month January = std::chrono::January;
33
34 for (int i = 1000; i <= 1010; ++i) {
35 year_month_weekday ymwd(year{i}, January, weekday_indexed{Tuesday, 2});
36
37 assert(static_cast<int>((ymwd += years{2}).year()) == i + 2);
38 assert(ymwd.month() == January);
39 assert(ymwd.weekday() == Tuesday);
40 assert(ymwd.index() == 2);
41
42 assert(static_cast<int>((ymwd).year()) == i + 2);
43 assert(ymwd.month() == January);
44 assert(ymwd.weekday() == Tuesday);
45 assert(ymwd.index() == 2);
46
47 assert(static_cast<int>((ymwd -= years{1}).year()) == i + 1);
48 assert(ymwd.month() == January);
49 assert(ymwd.weekday() == Tuesday);
50 assert(ymwd.index() == 2);
51
52 assert(static_cast<int>((ymwd).year()) == i + 1);
53 assert(ymwd.month() == January);
54 assert(ymwd.weekday() == Tuesday);
55 assert(ymwd.index() == 2);
56 }
57 return true;
58}
59
60int main(int, char**) {
61 ASSERT_NOEXCEPT(std::declval<year_month_weekday&>() += std::declval<years>());
62 ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval<year_month_weekday&>() += std::declval<years>()));
63
64 ASSERT_NOEXCEPT(std::declval<year_month_weekday&>() -= std::declval<years>());
65 ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval<year_month_weekday&>() -= std::declval<years>()));
66
67 test();
68 static_assert(test());
69
70 return 0;
71}
72

source code of libcxx/test/std/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_year.pass.cpp