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