Debian Codegraph @

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