1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <chrono>
12 // class year_month_weekday;
13
14 // constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
15 // Returns: ymwd + (-dm).
16 //
17 // constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
18 // Returns: ymwd + (-dy).
19
20
21 #include <chrono>
22 #include <type_traits>
23 #include <cassert>
24
25 #include "test_macros.h"
26
27 #include <iostream>
28
testConstexprYears()29 constexpr bool testConstexprYears ()
30 {
31 std::chrono::year_month_weekday ym0{std::chrono::year{1234}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::Tuesday, 1}};
32 std::chrono::year_month_weekday ym1 = ym0 - std::chrono::years{10};
33 return
34 ym1.year() == std::chrono::year{1234-10}
35 && ym1.month() == std::chrono::January
36 && ym1.weekday() == std::chrono::Tuesday
37 && ym1.index() == 1
38 ;
39 }
40
testConstexprMonths()41 constexpr bool testConstexprMonths ()
42 {
43 std::chrono::year_month_weekday ym0{std::chrono::year{1234}, std::chrono::November, std::chrono::weekday_indexed{std::chrono::Tuesday, 1}};
44 std::chrono::year_month_weekday ym1 = ym0 - std::chrono::months{6};
45 return
46 ym1.year() == std::chrono::year{1234}
47 && ym1.month() == std::chrono::May
48 && ym1.weekday() == std::chrono::Tuesday
49 && ym1.index() == 1
50 ;
51 }
52
53
main()54 int main()
55 {
56 using year = std::chrono::year;
57 using month = std::chrono::month;
58 using weekday = std::chrono::weekday;
59 using weekday_indexed = std::chrono::weekday_indexed;
60 using year_month_weekday = std::chrono::year_month_weekday;
61 using years = std::chrono::years;
62 using months = std::chrono::months;
63
64 constexpr month November = std::chrono::November;
65 constexpr weekday Tuesday = std::chrono::Tuesday;
66
67 { // year_month_weekday - years
68 ASSERT_NOEXCEPT( std::declval<year_month_weekday>() - std::declval<years>());
69 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() - std::declval<years>()));
70
71 static_assert(testConstexprYears(), "");
72
73 year_month_weekday ym{year{1234}, November, weekday_indexed{Tuesday, 1}};
74 for (int i = 0; i <= 10; ++i)
75 {
76 year_month_weekday ym1 = ym - years{i};
77 assert(static_cast<int>(ym1.year()) == 1234 - i);
78 assert(ym1.month() == November);
79 assert(ym1.weekday() == Tuesday);
80 assert(ym1.index() == 1);
81 }
82 }
83
84 { // year_month_weekday - months
85 ASSERT_NOEXCEPT( std::declval<year_month_weekday>() - std::declval<months>());
86 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() - std::declval<months>()));
87
88 static_assert(testConstexprMonths(), "");
89
90 year_month_weekday ym{year{1234}, November, weekday_indexed{Tuesday, 2}};
91 for (unsigned i = 1; i <= 10; ++i)
92 {
93 year_month_weekday ym1 = ym - months{i};
94 assert(ym1.year() == year{1234});
95 assert(ym1.month() == month{11-i});
96 assert(ym1.weekday() == Tuesday);
97 assert(ym1.index() == 2);
98 }
99 }
100 }
101