Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.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_day_last;
12
13 // constexpr year_month_day_last
14 // operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
15 //
16 // Returns: ymdl + (-dm).
17 //
18 // constexpr year_month_day_last
19 // operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
20 //
21 // Returns: ymdl + (-dy).
22
23 #include <chrono>
24 #include <type_traits>
25 #include <cassert>
26
27 #include "test_macros.h"
28
29 using year = std::chrono::year;
30 using month = std::chrono::month;
31 using month_day_last = std::chrono::month_day_last;
32 using year_month_day_last = std::chrono::year_month_day_last;
33 using months = std::chrono::months;
34 using years = std::chrono::years;
35
36 constexpr bool test() {
37 constexpr month December = std::chrono::December;
38
39 { // year_month_day_last - years
40
41 year_month_day_last ymdl{year{1234}, month_day_last{December}};
42 for (int i = 0; i <= 10; ++i) {
43 year_month_day_last ymdl1 = ymdl - years{i};
44 assert(static_cast<int>(ymdl1.year()) == 1234 - i);
45 assert(ymdl1.month() == December);
46 }
47 }
48
49 { // year_month_day_last - months
50
51 year_month_day_last ymdl{year{1234}, month_day_last{December}};
52 for (unsigned i = 0; i <= 10; ++i) {
53 year_month_day_last ymdl1 = ymdl - months{i};
54 assert(static_cast<int>(ymdl1.year()) == 1234);
55 assert(static_cast<unsigned>(ymdl1.month()) == 12U - i);
56 }
57 // Test the year wraps around.
58 for (unsigned i = 12; i <= 15; ++i) {
59 year_month_day_last ymdl1 = ymdl - months{i};
60 assert(static_cast<int>(ymdl1.year()) == 1233);
61 assert(static_cast<unsigned>(ymdl1.month()) == 12U - i + 12);
62 }
63 }
64
65 return true;
66 }
67
68 int main(int, char**) {
69 // year_month_day_last - years
70 ASSERT_NOEXCEPT(std::declval<year_month_day_last>() - std::declval<years>());
71 ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() - std::declval<years>()));
72
73 // year_month_day_last - months
74 ASSERT_NOEXCEPT(std::declval<year_month_day_last>() - std::declval<months>());
75 ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() - std::declval<months>()));
76
77 test();
78 static_assert(test());
79
80 return 0;
81 }