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 _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval,
36 const chrono::weekday_indexed& __wdival) noexcept
37 : __m_{__mval}, __wdi_{__wdival} {}
38 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
39 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
40 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); }
41};
42
43_LIBCPP_HIDE_FROM_ABI inline constexpr bool
44operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept {
45 return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed();
46}
47
48_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday
49operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept {
50 return month_weekday{__lhs, __rhs};
51}
52
53_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept {
54 return month_weekday{month(__lhs), __rhs};
55}
56
57_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday
58operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept {
59 return month_weekday{__rhs, __lhs};
60}
61
62_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept {
63 return month_weekday{month(__rhs), __lhs};
64}
65
66class month_weekday_last {
67 chrono::month __m_;
68 chrono::weekday_last __wdl_;
69
70public:
71 _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval,
72 const chrono::weekday_last& __wdlval) noexcept
73 : __m_{__mval}, __wdl_{__wdlval} {}
74 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
75 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
76 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); }
77};
78
79_LIBCPP_HIDE_FROM_ABI inline constexpr bool
80operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept {
81 return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last();
82}
83
84_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last
85operator/(const month& __lhs, const weekday_last& __rhs) noexcept {
86 return month_weekday_last{__lhs, __rhs};
87}
88
89_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept {
90 return month_weekday_last{month(__lhs), __rhs};
91}
92
93_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last
94operator/(const weekday_last& __lhs, const month& __rhs) noexcept {
95 return month_weekday_last{__rhs, __lhs};
96}
97
98_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept {
99 return month_weekday_last{month(__rhs), __lhs};
100}
101} // namespace chrono
102
103# if _LIBCPP_STD_VER >= 26
104
105template <>
106struct hash<chrono::month_weekday> {
107 _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday& __mw) noexcept {
108 return std::__hash_combine(
109 hash<chrono::month>{}(__mw.month()), hash<chrono::weekday_indexed>{}(__mw.weekday_indexed()));
110 }
111};
112
113template <>
114struct hash<chrono::month_weekday_last> {
115 _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept {
116 return std::__hash_combine(
117 hash<chrono::month>{}(__mwl.month()), hash<chrono::weekday_last>{}(__mwl.weekday_last()));
118 }
119};
120
121# endif // _LIBCPP_STD_VER >= 26
122
123_LIBCPP_END_NAMESPACE_STD
124
125#endif // _LIBCPP_STD_VER >= 20
126
127#endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H