Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_year.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;
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 <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 using month = std::chrono::month;
23 using year = std::chrono::year;
24 using years = std::chrono::years;
25 using year_month = std::chrono::year_month;
26
27 constexpr bool test() {
28 for (int i = 1000; i <= 1010; ++i) {
29 month m{2};
30 year_month ym(year{i}, m);
31 assert(static_cast<int>((ym += years{2}).year()) == i + 2);
32 assert(ym.month() == m);
33 assert(static_cast<int>((ym).year()) == i + 2);
34 assert(ym.month() == m);
35 assert(static_cast<int>((ym -= years{1}).year()) == i + 1);
36 assert(ym.month() == m);
37 assert(static_cast<int>((ym).year()) == i + 1);
38 assert(ym.month() == m);
39 }
40
41 return true;
42 }
43
44 int main(int, char**) {
45 ASSERT_NOEXCEPT(std::declval<year_month&>() += std::declval<years>());
46 ASSERT_SAME_TYPE(year_month&, decltype(std::declval<year_month&>() += std::declval<years>()));
47
48 ASSERT_NOEXCEPT(std::declval<year_month&>() -= std::declval<years>());
49 ASSERT_SAME_TYPE(year_month&, decltype(std::declval<year_month&>() -= std::declval<years>()));
50
51 test();
52 static_assert(test());
53
54 return 0;
55 }