| 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 day; |
| 12 |
|
| 13 |
// constexpr day operator-(const day& x, const days& y) noexcept; |
| 14 |
// Returns: x + -y. |
| 15 |
// |
| 16 |
// constexpr days operator-(const day& x, const day& y) noexcept; |
| 17 |
// Returns: days{int(unsigned{x}) - int(unsigned{y}). |
| 18 |
|
| 19 |
#include <chrono> |
| 20 |
#include <type_traits> |
| 21 |
#include <cassert> |
| 22 |
|
| 23 |
#include "test_macros.h" |
| 24 |
|
| 25 |
using day = std::chrono::day; |
| 26 |
using days = std::chrono::days; |
| 27 |
|
| 28 |
constexpr bool test() { |
| 29 |
day dy{12}; |
| 30 |
for (unsigned i = 0; i <= 10; ++i) { |
| 31 |
day d1 = dy - days{i}; |
| 32 |
days off = dy - day{i}; |
| 33 |
assert(static_cast<unsigned>(d1) == 12 - i); |
| 34 |
assert(off.count() == static_cast<int>(12 - i)); // days is signed |
| 35 |
} |
| 36 |
|
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
int main(int, char**) { |
| 41 |
ASSERT_NOEXCEPT(std::declval<day>() - std::declval<days>()); |
| 42 |
ASSERT_NOEXCEPT(std::declval<day>() - std::declval<day>()); |
| 43 |
|
| 44 |
ASSERT_SAME_TYPE(day, decltype(std::declval<day>() - std::declval<days>())); |
| 45 |
ASSERT_SAME_TYPE(days, decltype(std::declval<day>() - std::declval<day>())); |
| 46 |
|
| 47 |
test(); |
| 48 |
static_assert(test()); |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |