| 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 month_day_last; |
| 12 |
|
| 13 |
// constexpr month_day_last |
| 14 |
// operator/(const month& m, last_spec) noexcept; |
| 15 |
// Returns: month_day_last{m}. |
| 16 |
// |
| 17 |
// constexpr month_day_last |
| 18 |
// operator/(int m, last_spec) noexcept; |
| 19 |
// Returns: month(m) / last. |
| 20 |
// |
| 21 |
// constexpr month_day_last |
| 22 |
// operator/(last_spec, const month& m) noexcept; |
| 23 |
// Returns: m / last. |
| 24 |
// |
| 25 |
// constexpr month_day_last |
| 26 |
// operator/(last_spec, int m) noexcept; |
| 27 |
// Returns: month(m) / last. |
| 28 |
// |
| 29 |
// |
| 30 |
// [Note: A month_day_last object can be constructed using the expression m/last or last/m, |
| 31 |
// where m is an expression of type month. - end note] |
| 32 |
// [Example: |
| 33 |
// constexpr auto mdl = February/last; // mdl is the last day of February of an as yet unspecified year |
| 34 |
// static_assert(mdl.month() == February); |
| 35 |
// --end example] |
| 36 |
|
| 37 |
#include <chrono> |
| 38 |
#include <type_traits> |
| 39 |
#include <cassert> |
| 40 |
|
| 41 |
#include "test_macros.h" |
| 42 |
|
| 43 |
int main(int, char**) |
| 44 |
{ |
| 45 |
using month = std::chrono::month; |
| 46 |
using month_day_last = std::chrono::month_day_last; |
| 47 |
|
| 48 |
constexpr month February = std::chrono::February; |
| 49 |
constexpr std::chrono::last_spec last = std::chrono::last; |
| 50 |
|
| 51 |
ASSERT_SAME_TYPE(month_day_last, decltype(last/February)); |
| 52 |
ASSERT_SAME_TYPE(month_day_last, decltype(February/last)); |
| 53 |
|
| 54 |
// Run the example |
| 55 |
{ |
| 56 |
constexpr auto mdl = February/std::chrono::last; |
| 57 |
static_assert(mdl.month() == February, ""); |
| 58 |
} |
| 59 |
|
| 60 |
{ // operator/(const month& m, last_spec) and switched |
| 61 |
ASSERT_NOEXCEPT ( last/February); |
| 62 |
ASSERT_SAME_TYPE(month_day_last, decltype(last/February)); |
| 63 |
ASSERT_NOEXCEPT ( February/last); |
| 64 |
ASSERT_SAME_TYPE(month_day_last, decltype(February/last)); |
| 65 |
|
| 66 |
static_assert((last/February).month() == February, ""); |
| 67 |
static_assert((February/last).month() == February, ""); |
| 68 |
|
| 69 |
for (unsigned i = 1; i < 12; ++i) |
| 70 |
{ |
| 71 |
month m{i}; |
| 72 |
month_day_last mdl1 = last/m; |
| 73 |
month_day_last mdl2 = m/last; |
| 74 |
assert(mdl1.month() == m); |
| 75 |
assert(mdl2.month() == m); |
| 76 |
assert(mdl1 == mdl2); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
{ // operator/(int, last_spec) and switched |
| 81 |
ASSERT_NOEXCEPT ( last/2); |
| 82 |
ASSERT_SAME_TYPE(month_day_last, decltype(last/2)); |
| 83 |
ASSERT_NOEXCEPT ( 2/last); |
| 84 |
ASSERT_SAME_TYPE(month_day_last, decltype(2/last)); |
| 85 |
|
| 86 |
static_assert((last/2).month() == February, ""); |
| 87 |
static_assert((2/last).month() == February, ""); |
| 88 |
|
| 89 |
for (unsigned i = 1; i < 12; ++i) |
| 90 |
{ |
| 91 |
month m{i}; |
| 92 |
month_day_last mdl1 = last/i; |
| 93 |
month_day_last mdl2 = i/last; |
| 94 |
assert(mdl1.month() == m); |
| 95 |
assert(mdl2.month() == m); |
| 96 |
assert(mdl1 == mdl2); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
return 0; |
| 102 |
} |