Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __chrono / day.h
blobc907c036c146ad08e52f7ac461ca32de7be280ce
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_DAY_H
11 #define _LIBCPP___CHRONO_DAY_H
13 #include <__chrono/duration.h>
14 #include <__config>
15 #include <compare>
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
28 class day {
29 private:
30 unsigned char __d_;
31 public:
32 day() = default;
33 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d_(static_cast<unsigned char>(__val)) {}
34 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d_; return *this; }
35 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
36 _LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d_; return *this; }
37 _LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
38 _LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept;
39 _LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept;
40 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; }
41 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; }
45 _LIBCPP_HIDE_FROM_ABI inline constexpr
46 bool operator==(const day& __lhs, const day& __rhs) noexcept
47 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
49 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
50 return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
53 _LIBCPP_HIDE_FROM_ABI inline constexpr
54 day operator+ (const day& __lhs, const days& __rhs) noexcept
55 { return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
57 _LIBCPP_HIDE_FROM_ABI inline constexpr
58 day operator+ (const days& __lhs, const day& __rhs) noexcept
59 { return __rhs + __lhs; }
61 _LIBCPP_HIDE_FROM_ABI inline constexpr
62 day operator- (const day& __lhs, const days& __rhs) noexcept
63 { return __lhs + -__rhs; }
65 _LIBCPP_HIDE_FROM_ABI inline constexpr
66 days operator-(const day& __lhs, const day& __rhs) noexcept
67 { return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
68 static_cast<int>(static_cast<unsigned>(__rhs))); }
70 _LIBCPP_HIDE_FROM_ABI inline constexpr
71 day& day::operator+=(const days& __dd) noexcept
72 { *this = *this + __dd; return *this; }
74 _LIBCPP_HIDE_FROM_ABI inline constexpr
75 day& day::operator-=(const days& __dd) noexcept
76 { *this = *this - __dd; return *this; }
78 } // namespace chrono
80 _LIBCPP_END_NAMESPACE_STD
82 #endif // _LIBCPP_STD_VER >= 20
84 #endif // _LIBCPP___CHRONO_DAY_H