1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_MONTH_WEEKDAY_H
11#define _LIBCPP___CHRONO_MONTH_WEEKDAY_H
12
13#include <__chrono/month.h>
14#include <__chrono/weekday.h>
15#include <__config>
16#include <__cstddef/size_t.h>
17#include <__functional/hash.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23#if _LIBCPP_STD_VER >= 20
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27namespace chrono {
28
29class month_weekday {
30private:
31 chrono::month __m_;
32 chrono::weekday_indexed __wdi_;
33
34public:
35 constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
36 : __m_{__mval}, __wdi_{__wdival} {}
37 [[nodiscard]] inline constexpr chrono::month month() const noexcept { return __m_; }
38 [[nodiscard]] inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
39 [[nodiscard]] inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); }
40};
41
42inline constexpr bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept {
43 return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed();
44}
45
46[[nodiscard]] inline constexpr month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept {
47 return month_weekday{__lhs, __rhs};
48}
49
50[[nodiscard]] inline constexpr month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept {
51 return month_weekday{month(__lhs), __rhs};
52}
53
54[[nodiscard]] inline constexpr month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept {
55 return month_weekday{__rhs, __lhs};
56}
57
58[[nodiscard]] inline constexpr month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept {
59 return month_weekday{month(__rhs), __lhs};
60}
61
62class month_weekday_last {
63 chrono::month __m_;
64 chrono::weekday_last __wdl_;
65
66public:
67 constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
68 : __m_{__mval}, __wdl_{__wdlval} {}
69 [[nodiscard]] inline constexpr chrono::month month() const noexcept { return __m_; }
70 [[nodiscard]] inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
71 [[nodiscard]] inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); }
72};
73
74inline constexpr bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept {
75 return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last();
76}
77
78[[nodiscard]] inline constexpr month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept {
79 return month_weekday_last{__lhs, __rhs};
80}
81
82[[nodiscard]] inline constexpr month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept {
83 return month_weekday_last{month(__lhs), __rhs};
84}
85
86[[nodiscard]] inline constexpr month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept {
87 return month_weekday_last{__rhs, __lhs};
88}
89
90[[nodiscard]] inline constexpr month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept {
91 return month_weekday_last{month(__rhs), __lhs};
92}
93} // namespace chrono
94
95# if _LIBCPP_STD_VER >= 26
96
97template <>
98struct hash<chrono::month_weekday> {
99 [[nodiscard]] static size_t operator()(const chrono::month_weekday& __mw) noexcept {
100 return std::__hash_combine(
101 lhs: hash<chrono::month>{}(__mw.month()), rhs: hash<chrono::weekday_indexed>{}(__mw.weekday_indexed()));
102 }
103};
104
105template <>
106struct hash<chrono::month_weekday_last> {
107 [[nodiscard]] static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept {
108 return std::__hash_combine(
109 lhs: hash<chrono::month>{}(__mwl.month()), rhs: hash<chrono::weekday_last>{}(__mwl.weekday_last()));
110 }
111};
112
113# endif // _LIBCPP_STD_VER >= 26
114
115_LIBCPP_END_NAMESPACE_STD
116
117#endif // _LIBCPP_STD_VER >= 20
118
119#endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H
120