65 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 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 range18// [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 <cassert>24#include <type_traits>25#include <utility>26 27#include "test_macros.h"28#include "../../euclidian.h"29 30using weekday = std::chrono::weekday;31using days = std::chrono::days;32 33constexpr bool test() {34 for (unsigned i = 0; i <= 6; ++i)35 for (unsigned j = 0; j <= 6; ++j) {36 weekday wd = weekday{i} - days{j};37 assert(wd + days{j} == weekday{i});38 assert((wd.c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, j)));39 }40 41 for (unsigned i = 0; i <= 6; ++i)42 for (unsigned j = 0; j <= 6; ++j) {43 days d = weekday{j} - weekday{i};44 assert(weekday{i} + d == weekday{j});45 }46 47 // Check the example48 assert(weekday{0} - weekday{1} == days{6});49 50 return true;51}52 53int main(int, char**) {54 ASSERT_NOEXCEPT(std::declval<weekday>() - std::declval<days>());55 ASSERT_SAME_TYPE(weekday, decltype(std::declval<weekday>() - std::declval<days>()));56 57 ASSERT_NOEXCEPT(std::declval<weekday>() - std::declval<weekday>());58 ASSERT_SAME_TYPE(days, decltype(std::declval<weekday>() - std::declval<weekday>()));59 60 test();61 static_assert(test());62 63 return 0;64}65