[libcxx-commits] [libcxx] [libc++][chrono] Implement LWG 4274: Allow chrono::hh_mm_ss to be constructed from unsigned durations (PR #209686)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 24 04:44:09 PDT 2026


================
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <chrono>
+//
+// template<class Duration>
+// class hh_mm_ss {
+// public:
+//   constexpr explicit hh_mm_ss(Duration d);
+// };
+//
+// LWG4274: The hh_mm_ss constructor supports unsigned durations.
+
+#include <chrono>
+#include <ratio>
+
+// A signed arithmetic-like type used as a custom duration representation.
+struct SignedRep {
+  long long value;
+
+  constexpr explicit SignedRep(long long v = 0) : value(v) {}
+  constexpr operator long long() const { return value; }
+
+  friend constexpr SignedRep operator-(SignedRep v) { return SignedRep{-v.value}; }
+  friend constexpr bool operator<(SignedRep lhs, SignedRep rhs) { return lhs.value < rhs.value; }
+};
----------------
frederick-vs-ja wrote:

This stuff looks completely irrelevant to LWG4274. Can we avoid it?

https://github.com/llvm/llvm-project/pull/209686


More information about the libcxx-commits mailing list