| 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 year_month_weekday_last& ymwdl, const months& dm) noexcept; |
| 14 |
// Returns: ymwdl + (-dm). |
| 15 |
// |
| 16 |
// constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; |
| 17 |
// Returns: ymwdl + (-dy). |
| 18 |
|
| 19 |
#include <chrono> |
| 20 |
#include <cassert> |
| 21 |
#include <type_traits> |
| 22 |
#include <utility> |
| 23 |
|
| 24 |
#include "test_macros.h" |
| 25 |
|
| 26 |
using year = std::chrono::year; |
| 27 |
using month = std::chrono::month; |
| 28 |
using weekday = std::chrono::weekday; |
| 29 |
using weekday_last = std::chrono::weekday_last; |
| 30 |
using year_month_weekday_last = std::chrono::year_month_weekday_last; |
| 31 |
using years = std::chrono::years; |
| 32 |
using months = std::chrono::months; |
| 33 |
|
| 34 |
constexpr bool test() { |
| 35 |
constexpr month October = std::chrono::October; |
| 36 |
constexpr weekday Tuesday = std::chrono::Tuesday; |
| 37 |
|
| 38 |
{ // year_month_weekday_last - years |
| 39 |
year_month_weekday_last ymwdl{year{1234}, October, weekday_last{Tuesday}}; |
| 40 |
for (int i = 0; i <= 10; ++i) { |
| 41 |
year_month_weekday_last ymwdl1 = ymwdl - years{i}; |
| 42 |
assert(ymwdl1.year() == year{1234 - i}); |
| 43 |
assert(ymwdl1.month() == October); |
| 44 |
assert(ymwdl1.weekday() == Tuesday); |
| 45 |
assert(ymwdl1.weekday_last() == weekday_last{Tuesday}); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
{ // year_month_weekday_last - months |
| 50 |
year_month_weekday_last ymwdl{year{1234}, October, weekday_last{Tuesday}}; |
| 51 |
for (unsigned i = 0; i < 10; ++i) { |
| 52 |
year_month_weekday_last ymwdl1 = ymwdl - months{i}; |
| 53 |
assert(ymwdl1.year() == year{1234}); |
| 54 |
assert(ymwdl1.month() == month{10 - i}); |
| 55 |
assert(ymwdl1.weekday() == Tuesday); |
| 56 |
assert(ymwdl1.weekday_last() == weekday_last{Tuesday}); |
| 57 |
} |
| 58 |
// Test the year wraps around. |
| 59 |
for (unsigned i = 12; i < 15; ++i) { |
| 60 |
year_month_weekday_last ymwdl1 = ymwdl - months{i}; |
| 61 |
assert(ymwdl1.year() == year{1233}); |
| 62 |
assert(ymwdl1.month() == month{10 - i + 12}); |
| 63 |
assert(ymwdl1.weekday() == Tuesday); |
| 64 |
assert(ymwdl1.weekday_last() == weekday_last{Tuesday}); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
int main(int, char**) { |
| 72 |
// year_month_weekday_last - years |
| 73 |
ASSERT_NOEXCEPT(std::declval<year_month_weekday_last>() - std::declval<years>()); |
| 74 |
ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval<year_month_weekday_last>() - std::declval<years>())); |
| 75 |
|
| 76 |
// year_month_weekday_last - months |
| 77 |
ASSERT_NOEXCEPT(std::declval<year_month_weekday_last>() - std::declval<months>()); |
| 78 |
ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval<year_month_weekday_last>() - std::declval<months>())); |
| 79 |
|
| 80 |
test(); |
| 81 |
static_assert(test()); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |