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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 29 20:57:49 PDT 2025


================
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <chrono>
+
+// Test that <chrono> provides all of the hash specializations.
+
+#include <chrono>
+#include "poisoned_hash_helper.h"
+
+int main(int, char**) {
+  test_hash_enabled<std::chrono::nanoseconds>();
+  test_hash_enabled<std::chrono::microseconds>();
+  test_hash_enabled<std::chrono::milliseconds>();
+  test_hash_enabled<std::chrono::seconds>();
+  test_hash_enabled<std::chrono::minutes>();
+  test_hash_enabled<std::chrono::hours>();
+  test_hash_enabled<std::chrono::days>();
+  test_hash_enabled<std::chrono::weeks>();
+  test_hash_enabled<std::chrono::months>();
+  test_hash_enabled<std::chrono::years>();
+
+  test_hash_enabled<std::chrono::day>();
+  test_hash_enabled<std::chrono::month>();
+  test_hash_enabled<std::chrono::year>();
+
+  test_hash_enabled<std::chrono::weekday>();
+  test_hash_enabled<std::chrono::weekday_indexed>();
+  test_hash_enabled(std::chrono::weekday_last(std::chrono::weekday{}));
+
+  test_hash_enabled<std::chrono::month_day>();
+  test_hash_enabled(std::chrono::month_day_last(std::chrono::month{}));
+
+  test_hash_enabled(std::chrono::month_weekday(std::chrono::month{}, std::chrono::weekday_indexed{}));
+
+  test_hash_enabled(
+      std::chrono::month_weekday_last(std::chrono::month{}, std::chrono::weekday_last(std::chrono::weekday{})));
+
+  test_hash_enabled<std::chrono::year_month>();
+
+  test_hash_enabled<std::chrono::year_month_day>();
+
+  test_hash_enabled(
+      std::chrono::year_month_day_last(std::chrono::year{}, std::chrono::month_day_last(std::chrono::month{})));
+
+  test_hash_enabled<std::chrono::year_month_weekday>();
+
+  test_hash_enabled(std::chrono::year_month_weekday_last(
+      std::chrono::year{}, std::chrono::month{}, std::chrono::weekday_last(std::chrono::weekday{})));
+
+  test_hash_enabled(std::chrono::leap_second({}, std::chrono::sys_seconds{}, std::chrono::seconds{}));
----------------
frederick-vs-ja wrote:

Let's guard this with `#if !TEST_HAS_NO_TIME_ZONE_DATABASE && !TEST_HAS_NO_FILESYSTEM && !TEST_HAS_NO_LOCALIZATION`.

Also, `hash<chrono::zoned_time>` should also be tested (within the same guard).

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


More information about the libcxx-commits mailing list