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;
12
13// constexpr year_month& operator+=(const years& d) noexcept;
14// constexpr year_month& 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 month = std::chrono::month;
24using year = std::chrono::year;
25using years = std::chrono::years;
26using year_month = std::chrono::year_month;
27
28constexpr bool test() {
29 for (int i = 1000; i <= 1010; ++i) {
30 month m{2};
31 year_month ym(year{i}, m);
32 assert(static_cast<int>((ym += years{2}).year()) == i + 2);
33 assert(ym.month() == m);
34 assert(static_cast<int>((ym).year()) == i + 2);
35 assert(ym.month() == m);
36 assert(static_cast<int>((ym -= years{1}).year()) == i + 1);
37 assert(ym.month() == m);
38 assert(static_cast<int>((ym).year()) == i + 1);
39 assert(ym.month() == m);
40 }
41
42 return true;
43}
44
45int main(int, char**) {
46 ASSERT_NOEXCEPT(std::declval<year_month&>() += std::declval<years>());
47 ASSERT_SAME_TYPE(year_month&, decltype(std::declval<year_month&>() += std::declval<years>()));
48
49 ASSERT_NOEXCEPT(std::declval<year_month&>() -= std::declval<years>());
50 ASSERT_SAME_TYPE(year_month&, decltype(std::declval<year_month&>() -= std::declval<years>()));
51
52 test();
53 static_assert(test());
54
55 return 0;
56}
57

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