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

source code of libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/minus.pass.cpp