1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
12 // class year_month_weekday;
14 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const months& dm) noexcept;
15 // Returns: (ymd.year() / ymd.month() + dm) / ymd.day().
17 // constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymd) noexcept;
21 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const years& dy) noexcept;
22 // Returns: (ymd.year() + dy) / ymd.month() / ymd.day().
24 // constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymd) noexcept;
30 #include <type_traits>
33 #include "test_macros.h"
35 constexpr bool testConstexprYears(std::chrono::year_month_weekday ym)
37 std::chrono::years offset{23};
38 if (static_cast<int>((ym ).year()) != 1) return false;
39 if (static_cast<int>((ym + offset).year()) != 24) return false;
40 if (static_cast<int>((offset + ym).year()) != 24) return false;
45 constexpr bool testConstexprMonths(std::chrono::year_month_weekday ym)
47 std::chrono::months offset{6};
48 if (static_cast<unsigned>((ym ).month()) != 1) return false;
49 if (static_cast<unsigned>((ym + offset).month()) != 7) return false;
50 if (static_cast<unsigned>((offset + ym).month()) != 7) return false;
57 using year = std::chrono::year;
58 using month = std::chrono::month;
59 using weekday = std::chrono::weekday;
60 using weekday_indexed = std::chrono::weekday_indexed;
61 using year_month_weekday = std::chrono::year_month_weekday;
62 using years = std::chrono::years;
63 using months = std::chrono::months;
65 constexpr weekday Tuesday = std::chrono::Tuesday;
66 constexpr month January = std::chrono::January;
68 { // year_month_weekday + months (and switched)
69 ASSERT_NOEXCEPT(std::declval<year_month_weekday>() + std::declval<months>());
70 ASSERT_NOEXCEPT(std::declval<months>() + std::declval<year_month_weekday>());
72 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() + std::declval<months>()));
73 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<months>() + std::declval<year_month_weekday>()));
75 static_assert(testConstexprMonths(year_month_weekday{year{1}, January, weekday_indexed{Tuesday, 1}}), "");
77 year_month_weekday ym{year{1234}, January, weekday_indexed{Tuesday, 3}};
78 for (int i = 0; i <= 10; ++i) // TODO test wrap-around
80 year_month_weekday ym1 = ym + months{i};
81 year_month_weekday ym2 = months{i} + ym;
82 assert(static_cast<int>(ym1.year()) == 1234);
83 assert(static_cast<int>(ym2.year()) == 1234);
84 assert(ym1.month() == month(1 + i));
85 assert(ym2.month() == month(1 + i));
86 assert(ym1.weekday() == Tuesday);
87 assert(ym2.weekday() == Tuesday);
88 assert(ym1.index() == 3);
89 assert(ym2.index() == 3);
94 { // year_month_weekday + years (and switched)
95 ASSERT_NOEXCEPT(std::declval<year_month_weekday>() + std::declval<years>());
96 ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year_month_weekday>());
98 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<year_month_weekday>() + std::declval<years>()));
99 ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval<years>() + std::declval<year_month_weekday>()));
101 static_assert(testConstexprYears (year_month_weekday{year{1}, January, weekday_indexed{Tuesday, 1}}), "");
103 year_month_weekday ym{year{1234}, std::chrono::January, weekday_indexed{Tuesday, 3}};
104 for (int i = 0; i <= 10; ++i)
106 year_month_weekday ym1 = ym + years{i};
107 year_month_weekday ym2 = years{i} + ym;
108 assert(static_cast<int>(ym1.year()) == i + 1234);
109 assert(static_cast<int>(ym2.year()) == i + 1234);
110 assert(ym1.month() == January);
111 assert(ym2.month() == January);
112 assert(ym1.weekday() == Tuesday);
113 assert(ym2.weekday() == Tuesday);
114 assert(ym1.index() == 3);
115 assert(ym2.index() == 3);