Debian Codegraph @

libcxx/include/__chrono/leap_second.h

raw
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 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11
12 #ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
13 #define _LIBCPP___CHRONO_LEAP_SECOND_H
14
15 #include <version>
16 // Enable the contents of the header only when libc++ was built with experimental features enabled.
17 #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
18
19 # include <__chrono/duration.h>
20 # include <__chrono/system_clock.h>
21 # include <__chrono/time_point.h>
22 # include <__compare/ordering.h>
23 # include <__compare/three_way_comparable.h>
24 # include <__config>
25 # include <__utility/private_constructor_tag.h>
26
27 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
29 # endif
30
31 _LIBCPP_BEGIN_NAMESPACE_STD
32
33 # if _LIBCPP_STD_VER >= 20
34
35 namespace chrono {
36
37 class leap_second {
38 public:
39 [[nodiscard]]
40 _LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_constructor_tag, sys_seconds __date, seconds __value)
41 : __date_(__date), __value_(__value) {}
42
43 _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default;
44 _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;
45
46 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
47
48 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }
49
50 private:
51 sys_seconds __date_;
52 seconds __value_;
53 };
54
55 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
56 return __x.date() == __y.date();
57 }
58
59 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
60 return __x.date() <=> __y.date();
61 }
62
63 template <class _Duration>
64 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {
65 return __x.date() == __y;
66 }
67
68 template <class _Duration>
69 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {
70 return __x.date() < __y;
71 }
72
73 template <class _Duration>
74 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {
75 return __x < __y.date();
76 }
77
78 template <class _Duration>
79 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {
80 return __y < __x;
81 }
82
83 template <class _Duration>
84 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {
85 return __y < __x;
86 }
87
88 template <class _Duration>
89 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {
90 return !(__y < __x);
91 }
92
93 template <class _Duration>
94 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {
95 return !(__y < __x);
96 }
97
98 template <class _Duration>
99 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {
100 return !(__x < __y);
101 }
102
103 template <class _Duration>
104 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {
105 return !(__x < __y);
106 }
107
108 # ifndef _LIBCPP_COMPILER_GCC
109 // This requirement cause a compilation loop in GCC-13 and running out of memory.
110 // TODO TZDB Test whether GCC-14 fixes this.
111 template <class _Duration>
112 requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
113 _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {
114 return __x.date() <=> __y;
115 }
116 # endif
117
118 } // namespace chrono
119
120 # endif //_LIBCPP_STD_VER >= 20
121
122 _LIBCPP_END_NAMESPACE_STD
123
124 #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
125
126 #endif // _LIBCPP___CHRONO_LEAP_SECOND_H