[libcxx-commits] [libcxx] [libcxx] Implement C++20 std::chrono::is_clock, std::chrono::is_clock_v (PR #160607)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 25 18:50:45 PDT 2025
================
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___CHRONO_IS_CLOCK_H
+#define _LIBCPP___CHRONO_IS_CLOCK_H
+
+#include <__config>
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_arithmetic.h>
+#include <__type_traits/is_same.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 20
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono {
+
+template <class _Rep, class _Period>
+class duration;
+
+template <class _Clock, class _Duration>
+class time_point;
+
+template <class _TimePoint, class _Clock>
+constexpr bool __is_valid_clock_time_point_v = false;
+
+template <class _Clock, class _Duration, class _ClockType>
+constexpr bool __is_valid_clock_time_point_v<time_point<_Clock, _Duration>, _ClockType> =
+ _IsSame<time_point<_Clock, _Duration>, time_point<_ClockType>>::value ||
----------------
frederick-vs-ja wrote:
We can manually add the template argument here:
```suggestion
_IsSame<time_point<_Clock, _Duration>, time_point<_ClockType, typename _ClockType::duration>>::value ||
```
However, it seems simpler to check the relationship between `_Tp::time_point` and `_Tp::duration`. I.e. `_Tp::time_point` must be of form `time_point<_Clock, typename _Tp::duration>`.
https://github.com/llvm/llvm-project/pull/160607
More information about the libcxx-commits
mailing list