| 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_last; |
| 12 |
|
| 13 |
// constexpr year_month_day_last& operator+=(const months& m) noexcept; |
| 14 |
// constexpr year_month_day_last& operator-=(const months& m) 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 month_day_last = std::chrono::month_day_last; |
| 25 |
using year_month_day_last = std::chrono::year_month_day_last; |
| 26 |
using months = std::chrono::months; |
| 27 |
|
| 28 |
constexpr bool test() { |
| 29 |
for (unsigned i = 0; i <= 10; ++i) { |
| 30 |
year y{1234}; |
| 31 |
month_day_last mdl{month{i}}; |
| 32 |
year_month_day_last ymdl(y, mdl); |
| 33 |
assert(static_cast<unsigned>((ymdl += months{2}).month()) == i + 2); |
| 34 |
assert(ymdl.year() == y); |
| 35 |
assert(static_cast<unsigned>((ymdl).month()) == i + 2); |
| 36 |
assert(ymdl.year() == y); |
| 37 |
assert(static_cast<unsigned>((ymdl -= months{1}).month()) == i + 1); |
| 38 |
assert(ymdl.year() == y); |
| 39 |
assert(static_cast<unsigned>((ymdl).month()) == i + 1); |
| 40 |
assert(ymdl.year() == y); |
| 41 |
} |
| 42 |
|
| 43 |
{ // Test year wrapping |
| 44 |
year_month_day_last ymdl{year{2020}, month_day_last{month{4}}}; |
| 45 |
|
| 46 |
ymdl += months{12}; |
| 47 |
assert((ymdl == year_month_day_last{year{2021}, month_day_last{month{4}}})); |
| 48 |
|
| 49 |
ymdl -= months{12}; |
| 50 |
assert((ymdl == year_month_day_last{year{2020}, month_day_last{month{4}}})); |
| 51 |
} |
| 52 |
|
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
int main(int, char**) { |
| 57 |
ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() += std::declval<months>()); |
| 58 |
ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() -= std::declval<months>()); |
| 59 |
|
| 60 |
ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() += std::declval<months>())); |
| 61 |
ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() -= std::declval<months>())); |
| 62 |
|
| 63 |
test(); |
| 64 |
static_assert(test()); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |