[libcxx-commits] [libcxx] [libc++][chrono] P2592R3: Hashing for chrono (PR #165132)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 26 20:30:22 PDT 2025


================
@@ -92,6 +93,17 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator-=(const days& __dd) no
 
 } // namespace chrono
 
+#  if _LIBCPP_STD_VER >= 26
+
+template <>
+struct hash<chrono::day> : public __unary_function<chrono::day, size_t> {
+  _LIBCPP_HIDE_FROM_ABI size_t operator()(const chrono::day& __d) const _NOEXCEPT {
----------------
frederick-vs-ja wrote:

We should use plain `noexcept` unless the function needs to be available in C++03 mode.

Also it's possible better to use `static` `operator()` which avoids passing `*this`.

```suggestion
  _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::day& __d) noexcept {
```

(ditto other `operator()`'s)

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


More information about the libcxx-commits mailing list