| 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; |
| 12 |
|
| 13 |
// constexpr year_month operator/(const year& y, const month& m) noexcept; |
| 14 |
// Returns: {y, m}. |
| 15 |
// |
| 16 |
// constexpr year_month operator/(const year& y, int m) noexcept; |
| 17 |
// Returns: y / month(m). |
| 18 |
|
| 19 |
#include <chrono> |
| 20 |
#include <type_traits> |
| 21 |
#include <cassert> |
| 22 |
|
| 23 |
#include "test_macros.h" |
| 24 |
|
| 25 |
int main(int, char**) |
| 26 |
{ |
| 27 |
using month = std::chrono::month; |
| 28 |
using year = std::chrono::year; |
| 29 |
using year_month = std::chrono::year_month; |
| 30 |
|
| 31 |
constexpr month February = std::chrono::February; |
| 32 |
|
| 33 |
{ // operator/(const year& y, const month& m) |
| 34 |
ASSERT_NOEXCEPT ( year{2018}/February); |
| 35 |
ASSERT_SAME_TYPE(year_month, decltype(year{2018}/February)); |
| 36 |
|
| 37 |
static_assert((year{2018}/February).year() == year{2018}, ""); |
| 38 |
static_assert((year{2018}/February).month() == month{2}, ""); |
| 39 |
for (int i = 1000; i <= 1030; ++i) |
| 40 |
for (unsigned j = 1; j <= 12; ++j) |
| 41 |
{ |
| 42 |
year_month ym = year{i}/month{j}; |
| 43 |
assert(static_cast<int>(ym.year()) == i); |
| 44 |
assert(static_cast<unsigned>(ym.month()) == j); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
{ // operator/(const year& y, const int m) |
| 50 |
ASSERT_NOEXCEPT ( year{2018}/4); |
| 51 |
ASSERT_SAME_TYPE(year_month, decltype(year{2018}/4)); |
| 52 |
|
| 53 |
static_assert((year{2018}/2).year() == year{2018}, ""); |
| 54 |
static_assert((year{2018}/2).month() == month{2}, ""); |
| 55 |
|
| 56 |
for (int i = 1000; i <= 1030; ++i) |
| 57 |
for (unsigned j = 1; j <= 12; ++j) |
| 58 |
{ |
| 59 |
year_month ym = year{i}/j; |
| 60 |
assert(static_cast<int>(ym.year()) == i); |
| 61 |
assert(static_cast<unsigned>(ym.month()) == j); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return 0; |
| 66 |
} |