Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / include / __chrono / monthday.h
blob57712cf0b65a8a25137086534ee474fe722865c7
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CHRONO_MONTHDAY_H
11 #define _LIBCPP___CHRONO_MONTHDAY_H
13 #include <__chrono/calendar.h>
14 #include <__chrono/day.h>
15 #include <__chrono/month.h>
16 #include <__compare/ordering.h>
17 #include <__config>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
21 #endif
23 #if _LIBCPP_STD_VER >= 20
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 namespace chrono {
29 class month_day {
30 private:
31 chrono::month __m_;
32 chrono::day __d_;
34 public:
35 month_day() = default;
36 _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
37 : __m_{__mval}, __d_{__dval} {}
38 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
39 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
40 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
43 _LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept {
44 if (!__m_.ok())
45 return false;
46 const unsigned __dval = static_cast<unsigned>(__d_);
47 if (__dval < 1 || __dval > 31)
48 return false;
49 if (__dval <= 29)
50 return true;
51 // Now we've got either 30 or 31
52 const unsigned __mval = static_cast<unsigned>(__m_);
53 if (__mval == 2)
54 return false;
55 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
56 return __dval == 30;
57 return true;
60 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept {
61 return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day();
64 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
65 operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
66 if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
67 return __c;
68 return __lhs.day() <=> __rhs.day();
71 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept {
72 return month_day{__lhs, __rhs};
75 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept {
76 return __rhs / __lhs;
79 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept {
80 return __lhs / day(__rhs);
83 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept {
84 return month(__lhs) / __rhs;
87 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept {
88 return month(__rhs) / __lhs;
91 class month_day_last {
92 private:
93 chrono::month __m_;
95 public:
96 _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {}
97 _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
98 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); }
101 _LIBCPP_HIDE_FROM_ABI inline constexpr bool
102 operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
103 return __lhs.month() == __rhs.month();
106 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
107 operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
108 return __lhs.month() <=> __rhs.month();
111 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept {
112 return month_day_last{__lhs};
115 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept {
116 return month_day_last{__rhs};
119 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept {
120 return month_day_last{month(__lhs)};
123 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept {
124 return month_day_last{month(__rhs)};
127 } // namespace chrono
129 _LIBCPP_END_NAMESPACE_STD
131 #endif // _LIBCPP_STD_VER >= 20
133 #endif // _LIBCPP___CHRONO_MONTHDAY_H