| 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; |
| 12 | |
| 13 | // constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; |
| 14 | // Returns: ymd + (-dy) |
| 15 | |
| 16 | |
| 17 | #include <chrono> |
| 18 | #include <cassert> |
| 19 | #include <type_traits> |
| 20 | #include <utility> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | |
| 24 | constexpr bool test_constexpr () |
| 25 | { |
| 26 | std::chrono::year_month_day ym0{std::chrono::year{1234}, std::chrono::January, std::chrono::day{12}}; |
| 27 | std::chrono::year_month_day ym1 = ym0 - std::chrono::years{10}; |
| 28 | return |
| 29 | ym1.year() == std::chrono::year{1234-10} |
| 30 | && ym1.month() == std::chrono::January |
| 31 | && ym1.day() == std::chrono::day{12} |
| 32 | ; |
| 33 | } |
| 34 | |
| 35 | int main(int, char**) |
| 36 | { |
| 37 | using year = std::chrono::year; |
| 38 | using month = std::chrono::month; |
| 39 | using day = std::chrono::day; |
| 40 | using year_month_day = std::chrono::year_month_day; |
| 41 | using years = std::chrono::years; |
| 42 | |
| 43 | ASSERT_NOEXCEPT( std::declval<year_month_day>() - std::declval<years>()); |
| 44 | ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() - std::declval<years>())); |
| 45 | |
| 46 | constexpr month January = std::chrono::January; |
| 47 | |
| 48 | static_assert(test_constexpr(), "" ); |
| 49 | |
| 50 | year_month_day ym{year{1234}, January, day{10}}; |
| 51 | for (int i = 0; i <= 10; ++i) |
| 52 | { |
| 53 | year_month_day ym1 = ym - years{i}; |
| 54 | assert(static_cast<int>(ym1.year()) == 1234 - i); |
| 55 | assert(ym1.month() == January); |
| 56 | assert(ym1.day() == day{10}); |
| 57 | } |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |