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_day_last;
12
13// constexpr year_month_day_last& operator+=(const months& m) noexcept;
14// constexpr year_month_day_last& operator-=(const months& m) 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 month_day_last = std::chrono::month_day_last;
26using year_month_day_last = std::chrono::year_month_day_last;
27using months = std::chrono::months;
28
29constexpr bool test() {
30 for (unsigned i = 0; i <= 10; ++i) {
31 year y{1234};
32 month_day_last mdl{month{i}};
33 year_month_day_last ymdl(y, mdl);
34 assert(static_cast<unsigned>((ymdl += months{2}).month()) == i + 2);
35 assert(ymdl.year() == y);
36 assert(static_cast<unsigned>((ymdl).month()) == i + 2);
37 assert(ymdl.year() == y);
38 assert(static_cast<unsigned>((ymdl -= months{1}).month()) == i + 1);
39 assert(ymdl.year() == y);
40 assert(static_cast<unsigned>((ymdl).month()) == i + 1);
41 assert(ymdl.year() == y);
42 }
43
44 { // Test year wrapping
45 year_month_day_last ymdl{year{2020}, month_day_last{month{4}}};
46
47 ymdl += months{12};
48 assert((ymdl == year_month_day_last{year{2021}, month_day_last{month{4}}}));
49
50 ymdl -= months{12};
51 assert((ymdl == year_month_day_last{year{2020}, month_day_last{month{4}}}));
52 }
53
54 return true;
55}
56
57int main(int, char**) {
58 ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() += std::declval<months>());
59 ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() -= std::declval<months>());
60
61 ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() += std::declval<months>()));
62 ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() -= std::declval<months>()));
63
64 test();
65 static_assert(test());
66
67 return 0;
68}
69

source code of libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_month.pass.cpp