[libcxx-commits] [libcxx] [libc++][TZDB] Adds basics of zoned_time class. (PR #94999)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 11 12:01:33 PDT 2024
================
@@ -43,13 +50,55 @@ struct zoned_traits<const time_zone*> {
}
};
+template <class _Duration, class _TimeZonePtr = const time_zone*>
+class zoned_time {
+ // [time.zone.zonedtime.ctor]/2
+ static_assert(__is_duration<_Duration>::value,
+ "the program is ill-formed since _Duration is not a specialization of std::chrono::duration");
+
+ using __traits = zoned_traits<_TimeZonePtr>;
+
+public:
+ using duration = common_type_t<_Duration, seconds>;
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time()
+ requires requires { __traits::default_zone(); }
+ : __zone_{__traits::default_zone()}, __tp_{} {}
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time&) = default;
+ _LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const zoned_time&) = default;
+
+ _LIBCPP_HIDE_FROM_ABI zoned_time(const sys_time<_Duration>& __tp)
+ requires requires { __traits::default_zone(); }
+ : __zone_{__traits::default_zone()}, __tp_{__tp} {}
+
+ _LIBCPP_HIDE_FROM_ABI explicit zoned_time(_TimeZonePtr __zone) : __zone_{std::move(__zone)}, __tp_{} {}
+
+ _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
+ requires(requires { __traits::locate_zone(string_view{}); } &&
+ // constructible_from<zoned_time, decltype(__traits::locate_zone(string_view{}))>
+ // would create a dependency on itself. Instead depend on the fact
+ // a constructor taking a _TimeZonePtr exists.
+ constructible_from<_TimeZonePtr, decltype(__traits::locate_zone(string_view{}))>)
----------------
ldionne wrote:
I don't understand this. The requirement in the Standard is `constructible_from<zoned_time, decltype(__traits::locate_zone(string_view{}))>` and I don't think there's anything circular with that unless `locate_zone` also returns a `string_view`. Am I missing something?
https://github.com/llvm/llvm-project/pull/94999
More information about the libcxx-commits
mailing list