| 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 years& d) noexcept; |
| 14 | // constexpr year_month_weekday_last& operator-=(const years& d) noexcept; |
| 15 | |
| 16 | #include <chrono> |
| 17 | #include <cassert> |
| 18 | #include <type_traits> |
| 19 | #include <utility> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | using year = std::chrono::year; |
| 24 | using month = std::chrono::month; |
| 25 | using weekday = std::chrono::weekday; |
| 26 | using weekday_last = std::chrono::weekday_last; |
| 27 | using year_month_weekday_last = std::chrono::year_month_weekday_last; |
| 28 | using years = std::chrono::years; |
| 29 | |
| 30 | constexpr bool test() { |
| 31 | constexpr weekday Tuesday = std::chrono::Tuesday; |
| 32 | constexpr month January = std::chrono::January; |
| 33 | |
| 34 | for (int i = 1000; i <= 1010; ++i) { |
| 35 | year_month_weekday_last ymwd(year{i}, January, weekday_last{Tuesday}); |
| 36 | |
| 37 | assert(static_cast<int>((ymwd += years{2}).year()) == i + 2); |
| 38 | assert(ymwd.month() == January); |
| 39 | assert(ymwd.weekday() == Tuesday); |
| 40 | |
| 41 | assert(static_cast<int>((ymwd).year()) == i + 2); |
| 42 | assert(ymwd.month() == January); |
| 43 | assert(ymwd.weekday() == Tuesday); |
| 44 | |
| 45 | assert(static_cast<int>((ymwd -= years{1}).year()) == i + 1); |
| 46 | assert(ymwd.month() == January); |
| 47 | assert(ymwd.weekday() == Tuesday); |
| 48 | |
| 49 | assert(static_cast<int>((ymwd).year()) == i + 1); |
| 50 | assert(ymwd.month() == January); |
| 51 | assert(ymwd.weekday() == Tuesday); |
| 52 | } |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | int main(int, char**) { |
| 58 | ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() += std::declval<years>()); |
| 59 | ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() -= std::declval<years>()); |
| 60 | |
| 61 | ASSERT_SAME_TYPE( |
| 62 | year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() += std::declval<years>())); |
| 63 | ASSERT_SAME_TYPE( |
| 64 | year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() -= std::declval<years>())); |
| 65 | |
| 66 | test(); |
| 67 | static_assert(test()); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |