[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


================
@@ -98,6 +99,24 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekda
 }
 } // namespace chrono
 
+#  if _LIBCPP_STD_VER >= 26
+
+template <>
+struct hash<chrono::month_weekday> : public __unary_function<chrono::month_weekday, size_t> {
+  _LIBCPP_HIDE_FROM_ABI size_t operator()(const chrono::month_weekday& __mw) const _NOEXCEPT {
+    return hash<chrono::month>{}(__mw.month()) ^ hash<chrono::weekday_indexed>{}(__mw.weekday_indexed());
----------------
frederick-vs-ja wrote:

It's possible better to use [`__hash_combile`](https://github.com/llvm/llvm-project/blob/279a81e240cb1f1633c1d800eb3705a5ba203dc7/libcxx/include/__functional/hash.h#L333-L337).

```suggestion
    return std::__hash_combine(
        hash<chrono::month>{}(__mw.month()), hash<chrono::weekday_indexed>{}(__mw.weekday_indexed()));
```

(ditto other hash combinations)

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


More information about the libcxx-commits mailing list