| 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 weekday; |
| 12 |
|
| 13 |
// constexpr weekday operator-(const weekday& x, const days& y) noexcept; |
| 14 |
// Returns: x + -y. |
| 15 |
// |
| 16 |
// constexpr days operator-(const weekday& x, const weekday& y) noexcept; |
| 17 |
// Returns: If x.ok() == true and y.ok() == true, returns a value d in the range |
| 18 |
// [days{0}, days{6}] satisfying y + d == x. |
| 19 |
// Otherwise the value returned is unspecified. |
| 20 |
// [Example: Sunday - Monday == days{6}. -end example] |
| 21 |
|
| 22 |
#include <chrono> |
| 23 |
#include <type_traits> |
| 24 |
#include <cassert> |
| 25 |
|
| 26 |
#include "test_macros.h" |
| 27 |
#include "../../euclidian.h" |
| 28 |
|
| 29 |
using weekday = std::chrono::weekday; |
| 30 |
using days = std::chrono::days; |
| 31 |
|
| 32 |
constexpr bool test() { |
| 33 |
for (unsigned i = 0; i <= 6; ++i) |
| 34 |
for (unsigned j = 0; j <= 6; ++j) { |
| 35 |
weekday wd = weekday{i} - days{j}; |
| 36 |
assert(wd + days{j} == weekday{i}); |
| 37 |
assert((wd.c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, j))); |
| 38 |
} |
| 39 |
|
| 40 |
for (unsigned i = 0; i <= 6; ++i) |
| 41 |
for (unsigned j = 0; j <= 6; ++j) { |
| 42 |
days d = weekday{j} - weekday{i}; |
| 43 |
assert(weekday{i} + d == weekday{j}); |
| 44 |
} |
| 45 |
|
| 46 |
// Check the example |
| 47 |
assert(weekday{0} - weekday{1} == days{6}); |
| 48 |
|
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
int main(int, char**) { |
| 53 |
ASSERT_NOEXCEPT(std::declval<weekday>() - std::declval<days>()); |
| 54 |
ASSERT_SAME_TYPE(weekday, decltype(std::declval<weekday>() - std::declval<days>())); |
| 55 |
|
| 56 |
ASSERT_NOEXCEPT(std::declval<weekday>() - std::declval<weekday>()); |
| 57 |
ASSERT_SAME_TYPE(days, decltype(std::declval<weekday>() - std::declval<weekday>())); |
| 58 |
|
| 59 |
test(); |
| 60 |
static_assert(test()); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |