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