| description | Learn more about is_clock struct | ||||
|---|---|---|---|---|---|
| title | is_clock class | ||||
| ms.date | 07/19/2021 | ||||
| f1_keywords |
|
||||
| helpviewer_keywords |
|
||||
| dev_langs |
|
A type trait that determines whether the specified type meets the requirements to be a clock.
template<class T> struct is_clock; // c++ 20Helper variable template
template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // c++ 20T
The type to test.
| Name | Description |
|---|---|
value |
Indicates whether T satisfies the requirements to be a clock. |
operator () |
Returns value. |
operator bool |
Returns value. |
A clock has a rep, period, duration, time_point, is_steady, and a now() function.
For more details about the requirements to be a C++17 clock, see Cpp17Clock requirements.
The following code works because is_clock, derives from Cpp17UnaryTypeTrait, which derives from integral_constant. This is where value_type, which is a bool, and type, which is a std::integral_constant<bool, value> come from.
#include <iostream>
#include <chrono>
using namespace `std::chrono`;
int main()
{
is_clock<system_clock> ic;
std::cout << std::boolalpha << ic.value << ", " << ic() << ", " << (bool)ic;
return 0;
}true, true, true
Header: <chrono>
Namespace: std::chrono
Compiler Option: /std:c++latest
Get whether the specified type satisfies the requirements to be a clock.
static constexpr T value;true if specified type meets the requirements to be a clock. Otherwise, false.
constexpr value_type operator()() const noexceptReturns value, that is, whether the specified type meets the requirements to be a clock.
true if specified type meets the requirements to be a clock. Otherwise, false.
constexpr operator value_type() const noexceptReturns value, that is, whether the specified type meets the requirements to be a clock.
true if specified type meets the requirements to be a clock. Otherwise, false.