Revert "[InstCombine] Support gep nuw in icmp folds" (#118698)
[llvm-project.git] / libcxx / include / __chrono / month.h
blob77c67d0954efa8fbfefa42b386950502b759532a
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_MONTH_H
11 #define _LIBCPP___CHRONO_MONTH_H
13 #include <__chrono/duration.h>
14 #include <__compare/ordering.h>
15 #include <__config>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
19 #endif
21 #if _LIBCPP_STD_VER >= 20
23 _LIBCPP_BEGIN_NAMESPACE_STD
25 namespace chrono {
27 class month {
28 private:
29 unsigned char __m_;
31 public:
32 month() = default;
33 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept
34 : __m_(static_cast<unsigned char>(__val)) {}
35 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept {
36 *this += months{1};
37 return *this;
39 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept {
40 month __tmp = *this;
41 ++(*this);
42 return __tmp;
44 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept {
45 *this -= months{1};
46 return *this;
48 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept {
49 month __tmp = *this;
50 --(*this);
51 return __tmp;
53 _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
54 _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
55 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; }
56 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; }
59 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept {
60 return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs);
63 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
64 return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
67 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept {
68 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
69 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
70 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
73 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept {
74 return __rhs + __lhs;
77 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept {
78 return __lhs + -__rhs;
81 _LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept {
82 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
83 return months(__dm <= 11 ? __dm : __dm + 12);
86 _LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator+=(const months& __dm) noexcept {
87 *this = *this + __dm;
88 return *this;
91 _LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator-=(const months& __dm) noexcept {
92 *this = *this - __dm;
93 return *this;
96 inline constexpr month January{1};
97 inline constexpr month February{2};
98 inline constexpr month March{3};
99 inline constexpr month April{4};
100 inline constexpr month May{5};
101 inline constexpr month June{6};
102 inline constexpr month July{7};
103 inline constexpr month August{8};
104 inline constexpr month September{9};
105 inline constexpr month October{10};
106 inline constexpr month November{11};
107 inline constexpr month December{12};
109 } // namespace chrono
111 _LIBCPP_END_NAMESPACE_STD
113 #endif // _LIBCPP_STD_VER >= 20
115 #endif // _LIBCPP___CHRONO_MONTH_H