| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CHRONO_IS_CLOCK_H |
| 11 | #define _LIBCPP___CHRONO_IS_CLOCK_H |
| 12 | |
| 13 | #include <__config> |
| 14 | |
| 15 | #include <__chrono/duration.h> |
| 16 | #include <__chrono/time_point.h> |
| 17 | #include <__concepts/same_as.h> |
| 18 | #include <__type_traits/integral_constant.h> |
| 19 | #include <__type_traits/is_arithmetic.h> |
| 20 | #include <__type_traits/is_class.h> |
| 21 | #include <__type_traits/is_union.h> |
| 22 | #include <ratio> |
| 23 | |
| 24 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 25 | # pragma GCC system_header |
| 26 | #endif |
| 27 | |
| 28 | #if _LIBCPP_STD_VER >= 20 |
| 29 | |
| 30 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 31 | |
| 32 | namespace chrono { |
| 33 | |
| 34 | // Helper to check that _Tp::time_point has the form time_point<_, typename _Tp::duration>. |
| 35 | template <class _TimePoint, class _ClockType> |
| 36 | inline constexpr bool __is_valid_clock_time_point_v = false; |
| 37 | |
| 38 | template <class _TimePointClock, class _ClockType> |
| 39 | inline constexpr bool |
| 40 | __is_valid_clock_time_point_v<time_point<_TimePointClock, typename _ClockType::duration>, _ClockType> = true; |
| 41 | |
| 42 | // Check if a clock satisfies the Cpp17Clock requirements as defined in [time.clock.req] |
| 43 | template <class _Tp> |
| 44 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_clock_v = requires { |
| 45 | typename _Tp::rep; |
| 46 | requires is_arithmetic_v<typename _Tp::rep> || is_class_v<typename _Tp::rep> || is_union_v<typename _Tp::rep>; |
| 47 | |
| 48 | typename _Tp::period; |
| 49 | requires __is_ratio_v<typename _Tp::period>; |
| 50 | |
| 51 | typename _Tp::duration; |
| 52 | requires same_as<typename _Tp::duration, duration<typename _Tp::rep, typename _Tp::period>>; |
| 53 | |
| 54 | typename _Tp::time_point; |
| 55 | requires __is_valid_clock_time_point_v<typename _Tp::time_point, _Tp>; |
| 56 | |
| 57 | _Tp::is_steady; |
| 58 | requires same_as<decltype((_Tp::is_steady)), const bool&>; |
| 59 | |
| 60 | _Tp::now(); |
| 61 | requires same_as<decltype(_Tp::now()), typename _Tp::time_point>; |
| 62 | }; |
| 63 | |
| 64 | template <class _Tp> |
| 65 | struct _LIBCPP_NO_SPECIALIZATIONS is_clock : bool_constant<is_clock_v<_Tp>> {}; |
| 66 | |
| 67 | } // namespace chrono |
| 68 | |
| 69 | _LIBCPP_END_NAMESPACE_STD |
| 70 | |
| 71 | #endif // _LIBCPP_STD_VER |
| 72 | #endif // _LIBCPP___CHRONO_IS_CLOCK_H |
| 73 | |