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_last;
12
13 // constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
14 // Returns: ymwdl + (-dm).
15 //
16 // constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
17 // Returns: ymwdl + (-dy).
18
19 #include <chrono>
20 #include <type_traits>
21 #include <cassert>
22
23 #include "test_macros.h"
24
25
testConstexprYears(std::chrono::year_month_weekday_last ym)26 constexpr bool testConstexprYears(std::chrono::year_month_weekday_last ym)
27 {
28 std::chrono::years offset{14};
29 if (static_cast<int>((ym ).year()) != 66) return false;
30 if (static_cast<int>((ym - offset).year()) != 52) return false;
31 return true;
32 }
33
testConstexprMonths(std::chrono::year_month_weekday_last ym)34 constexpr bool testConstexprMonths(std::chrono::year_month_weekday_last ym)
35 {
36 std::chrono::months offset{6};
37 if (static_cast<unsigned>((ym ).month()) != 10) return false;
38 if (static_cast<unsigned>((ym - offset).month()) != 4) return false;
39 return true;
40 }
41
main(int,char **)42 int main(int, char**)
43 {
44 using year = std::chrono::year;
45 using month = std::chrono::month;
46 using weekday = std::chrono::weekday;
47 using weekday_last = std::chrono::weekday_last;
48 using year_month_weekday_last = std::chrono::year_month_weekday_last;
49 using years = std::chrono::years;
50 using months = std::chrono::months;
51
52 constexpr month October = std::chrono::October;
53 constexpr weekday Tuesday = std::chrono::Tuesday;
54
55 { // year_month_weekday_last - years
56
57 ASSERT_NOEXCEPT( std::declval<year_month_weekday_last>() - std::declval<years>());
58 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval<year_month_weekday_last>() - std::declval<years>()));
59
60 static_assert(testConstexprYears(year_month_weekday_last{year{66}, October, weekday_last{Tuesday}}), "");
61
62 year_month_weekday_last ym{year{1234}, October, weekday_last{Tuesday}};
63 for (int i = 0; i <= 10; ++i)
64 {
65 year_month_weekday_last ym1 = ym - years{i};
66 assert(ym1.year() == year{1234 - i});
67 assert(ym1.month() == October);
68 assert(ym1.weekday() == Tuesday);
69 assert(ym1.weekday_last() == weekday_last{Tuesday});
70 }
71 }
72
73 { // year_month_weekday_last - months
74
75 ASSERT_NOEXCEPT( std::declval<year_month_weekday_last>() - std::declval<months>());
76 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval<year_month_weekday_last>() - std::declval<months>()));
77
78 static_assert(testConstexprMonths(year_month_weekday_last{year{66}, October, weekday_last{Tuesday}}), "");
79
80 year_month_weekday_last ym{year{1234}, October, weekday_last{Tuesday}};
81 for (unsigned i = 0; i < 10; ++i)
82 {
83 year_month_weekday_last ym1 = ym - months{i};
84 assert(ym1.year() == year{1234});
85 assert(ym1.month() == month{10 - i});
86 assert(ym1.weekday() == Tuesday);
87 assert(ym1.weekday_last() == weekday_last{Tuesday});
88 }
89 }
90
91
92 return 0;
93 }
94