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