1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // constexpr weekday operator-(const weekday& x, const days& y) noexcept;
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]
23 #include <type_traits>
26 #include "test_macros.h"
27 #include "../../euclidian.h"
29 using weekday
= std::chrono::weekday
;
30 using days
= std::chrono::days
;
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
)));
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
});
47 assert(weekday
{0} - weekday
{1} == days
{6});
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
>()));
56 ASSERT_NOEXCEPT(std::declval
<weekday
>() - std::declval
<weekday
>());
57 ASSERT_SAME_TYPE(days
, decltype(std::declval
<weekday
>() - std::declval
<weekday
>()));
60 static_assert(test());