Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / time / time.zone / time.zone.zonedtime / deduction.pass.cpp
blob3595d0a5f917eb5e9a8f884c0cb14210a013e7f3
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-filesystem, no-localization, no-tzdb
12 // XFAIL: libcpp-has-no-experimental-tzdb
13 // XFAIL: availability-tzdb-missing
15 // <chrono>
17 // zoned_time() -> zoned_time<seconds>;
19 // template<class Duration>
20 // zoned_time(sys_time<Duration>)
21 // -> zoned_time<common_type_t<Duration, seconds>>;
23 // template<class TimeZonePtrOrName>
24 // using time-zone-representation = // exposition only
25 // conditional_t<is_convertible_v<TimeZonePtrOrName, string_view>,
26 // const time_zone*,
27 // remove_cvref_t<TimeZonePtrOrName>>;
29 // template<class TimeZonePtrOrName>
30 // zoned_time(TimeZonePtrOrName&&)
31 // -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>;
33 // template<class TimeZonePtrOrName, class Duration>
34 // zoned_time(TimeZonePtrOrName&&, sys_time<Duration>)
35 // -> zoned_time<common_type_t<Duration, seconds>,
36 // time-zone-representation<TimeZonePtrOrName>>;
38 // template<class TimeZonePtrOrName, class Duration>
39 // zoned_time(TimeZonePtrOrName&&, local_time<Duration>,
40 // choose = choose::earliest)
41 // -> zoned_time<common_type_t<Duration, seconds>,
42 // time-zone-representation<TimeZonePtrOrName>>;
44 // template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2>
45 // zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>,
46 // choose = choose::earliest)
47 // -> zoned_time<common_type_t<Duration, seconds>,
48 // time-zone-representation<TimeZonePtrOrName>>;
50 #include <chrono>
51 #include <concepts>
52 #include <string>
54 #include "test_offset_time_zone.h"
56 namespace cr = std::chrono;
58 // Verify the results of the constructed object.
59 int main(int, char**) {
61 // zoned_time() -> zoned_time<seconds>;
62 cr::zoned_time zt;
63 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
67 // template<class Duration>
68 // zoned_time(sys_time<Duration>)
69 // -> zoned_time<common_type_t<Duration, seconds>>;
71 cr::zoned_time zt{cr::sys_time<cr::nanoseconds>{cr::nanoseconds{0}}};
72 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
75 cr::zoned_time zt{cr::sys_time<cr::seconds>{cr::seconds{0}}};
76 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
79 cr::zoned_time zt{cr::sys_time<cr::days>{cr::days{0}}};
80 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
85 // template<class TimeZonePtrOrName>
86 // zoned_time(TimeZonePtrOrName&&)
87 // -> zoned_time<seconds, time-zone-representation<TimeZonePtrOrName>>;
88 { // Name
90 cr::zoned_time zt{"UTC"};
91 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
94 cr::zoned_time zt{std::string{"UTC"}};
95 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
98 cr::zoned_time zt{std::string_view{"UTC"}};
99 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
102 { // TimeZonePtr
104 cr::zoned_time zt{static_cast<const cr::time_zone*>(nullptr)};
105 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
108 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::none>{}};
109 static_assert(
110 std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>>);
113 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::has_default_zone>{}};
114 static_assert(
115 std::same_as<decltype(zt),
116 cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>>);
119 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::has_locate_zone>{}};
120 static_assert(
121 std::same_as<decltype(zt),
122 cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>>);
125 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::both>{}};
126 static_assert(
127 std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::both>>>);
130 // There are no requirements on the TimeZonePtr type.
132 cr::zoned_time zt{0};
133 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, int>>);
136 cr::zoned_time zt{0.0};
137 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, double>>);
140 cr::zoned_time zt{cr::seconds{}};
141 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, cr::seconds>>);
147 // template<class TimeZonePtrOrName, class Duration>
148 // zoned_time(TimeZonePtrOrName&&, sys_time<Duration>)
149 // -> zoned_time<common_type_t<Duration, seconds>,
150 // time-zone-representation<TimeZonePtrOrName>>;
151 { // Name
153 cr::zoned_time zt{"UTC", cr::sys_time<cr::nanoseconds>{}};
154 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
157 cr::zoned_time zt{"UTC", cr::sys_time<cr::days>{}};
158 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
162 { // TimeZonePtr
164 cr::zoned_time zt{static_cast<const cr::time_zone*>(nullptr), cr::sys_time<cr::nanoseconds>{}};
165 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
168 cr::zoned_time zt{static_cast<const cr::time_zone*>(nullptr), cr::sys_time<cr::days>{}};
169 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
172 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::none>{}, cr::sys_time<cr::nanoseconds>{}};
173 static_assert(std::same_as< decltype(zt),
174 cr::zoned_time<cr::nanoseconds, offset_time_zone<offset_time_zone_flags::none>>>);
177 cr::zoned_time zt{offset_time_zone<offset_time_zone_flags::none>{}, cr::sys_time<cr::days>{}};
178 static_assert(
179 std::same_as< decltype(zt), cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>>);
185 // template<class TimeZonePtrOrName, class Duration>
186 // zoned_time(TimeZonePtrOrName&&, local_time<Duration>,
187 // choose = choose::earliest)
188 // -> zoned_time<common_type_t<Duration, seconds>,
189 // time-zone-representation<TimeZonePtrOrName>>;
190 { // Name
192 cr::zoned_time zt{"UTC", cr::local_time<cr::nanoseconds>{}};
193 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
196 cr::zoned_time zt{"UTC", cr::local_time<cr::days>{}, cr::choose::earliest};
197 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
200 { // TimeZonePtr
202 cr::zoned_time zt{cr::locate_zone("UTC"), cr::local_time<cr::nanoseconds>{}};
203 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
206 cr::zoned_time zt{cr::locate_zone("UTC"), cr::local_time<cr::days>{}, cr::choose::earliest};
207 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
213 // template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2>
214 // zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>,
215 // choose = choose::earliest)
216 // -> zoned_time<common_type_t<Duration, seconds>,
217 // time-zone-representation<TimeZonePtrOrName>>;
218 { // Name
220 cr::zoned_time zt{
221 "UTC", cr::zoned_time<cr::nanoseconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>{}};
222 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
225 cr::zoned_time zt{"UTC",
226 cr::zoned_time<cr::days, offset_time_zone<offset_time_zone_flags::has_default_zone>>{},
227 cr::choose::earliest};
228 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
231 { // TimeZonePtr
233 cr::zoned_time zt{
234 cr::locate_zone("UTC"),
235 cr::zoned_time<cr::nanoseconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>{}};
236 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::nanoseconds, const cr::time_zone*>>);
239 cr::zoned_time zt{cr::locate_zone("UTC"),
240 cr::zoned_time<cr::days, offset_time_zone<offset_time_zone_flags::has_default_zone>>{},
241 cr::choose::earliest};
242 static_assert(std::same_as<decltype(zt), cr::zoned_time<cr::seconds, const cr::time_zone*>>);
247 return 0;