| 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_day_last; |
| 12 | |
| 13 | // constexpr year_month_day_last |
| 14 | // operator+(const year_month_day_last& ymdl, const months& dm) noexcept; |
| 15 | // |
| 16 | // Returns: (ymdl.year() / ymdl.month() + dm) / last. |
| 17 | // |
| 18 | // constexpr year_month_day_last |
| 19 | // operator+(const months& dm, const year_month_day_last& ymdl) noexcept; |
| 20 | // |
| 21 | // Returns: ymdl + dm. |
| 22 | // |
| 23 | // |
| 24 | // constexpr year_month_day_last |
| 25 | // operator+(const year_month_day_last& ymdl, const years& dy) noexcept; |
| 26 | // |
| 27 | // Returns: {ymdl.year()+dy, ymdl.month_day_last()}. |
| 28 | // |
| 29 | // constexpr year_month_day_last |
| 30 | // operator+(const years& dy, const year_month_day_last& ymdl) noexcept; |
| 31 | // |
| 32 | // Returns: ymdl + dy |
| 33 | |
| 34 | #include <chrono> |
| 35 | #include <cassert> |
| 36 | #include <type_traits> |
| 37 | #include <utility> |
| 38 | |
| 39 | #include "test_macros.h" |
| 40 | |
| 41 | using year = std::chrono::year; |
| 42 | using month = std::chrono::month; |
| 43 | using month_day_last = std::chrono::month_day_last; |
| 44 | using year_month_day_last = std::chrono::year_month_day_last; |
| 45 | using months = std::chrono::months; |
| 46 | using years = std::chrono::years; |
| 47 | |
| 48 | constexpr bool test() { |
| 49 | constexpr month January = std::chrono::January; |
| 50 | |
| 51 | { // year_month_day_last + months |
| 52 | year_month_day_last ym{year{1234}, month_day_last{January}}; |
| 53 | for (int i = 0; i <= 10; ++i) { |
| 54 | year_month_day_last ymdl1 = ym + months{i}; |
| 55 | year_month_day_last ymdl2 = months{i} + ym; |
| 56 | assert(static_cast<int>(ymdl1.year()) == 1234); |
| 57 | assert(static_cast<int>(ymdl2.year()) == 1234); |
| 58 | assert(ymdl1.month() == month(1 + i)); |
| 59 | assert(ymdl2.month() == month(1 + i)); |
| 60 | assert(ymdl1 == ymdl2); |
| 61 | } |
| 62 | // Test the year wraps around. |
| 63 | for (int i = 12; i <= 15; ++i) { |
| 64 | year_month_day_last ymdl1 = ym + months{i}; |
| 65 | year_month_day_last ymdl2 = months{i} + ym; |
| 66 | assert(static_cast<int>(ymdl1.year()) == 1235); |
| 67 | assert(static_cast<int>(ymdl2.year()) == 1235); |
| 68 | assert(ymdl1.month() == month(1 + i - 12)); |
| 69 | assert(ymdl2.month() == month(1 + i - 12)); |
| 70 | assert(ymdl1 == ymdl2); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | { // year_month_day_last + years |
| 75 | year_month_day_last ym{year{1234}, month_day_last{January}}; |
| 76 | for (int i = 0; i <= 10; ++i) { |
| 77 | year_month_day_last ymdl1 = ym + years{i}; |
| 78 | year_month_day_last ymdl2 = years{i} + ym; |
| 79 | assert(static_cast<int>(ymdl1.year()) == i + 1234); |
| 80 | assert(static_cast<int>(ymdl2.year()) == i + 1234); |
| 81 | assert(ymdl1.month() == std::chrono::January); |
| 82 | assert(ymdl2.month() == std::chrono::January); |
| 83 | assert(ymdl1 == ymdl2); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | int main(int, char**) { |
| 91 | // year_month_day_last + months |
| 92 | ASSERT_NOEXCEPT(std::declval<year_month_day_last>() + std::declval<months>()); |
| 93 | ASSERT_NOEXCEPT(std::declval<months>() + std::declval<year_month_day_last>()); |
| 94 | |
| 95 | ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() + std::declval<months>())); |
| 96 | ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<months>() + std::declval<year_month_day_last>())); |
| 97 | |
| 98 | // year_month_day_last + years |
| 99 | ASSERT_NOEXCEPT(std::declval<year_month_day_last>() + std::declval<years>()); |
| 100 | ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year_month_day_last>()); |
| 101 | |
| 102 | ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() + std::declval<years>())); |
| 103 | ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<years>() + std::declval<year_month_day_last>())); |
| 104 | |
| 105 | test(); |
| 106 | static_assert(test()); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |