description | title | ms.date | f1_keywords | helpviewer_keywords | dev_langs | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about is_clock struct |
is_clock class |
07/19/2021 |
|
|
|
A type trait that determines whether the specified type meets the requirements to be a clock.
template<class T> struct is_clock; // C++20
Helper variable template
template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20
T
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;
}
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 noexcept
Returns 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 noexcept
Returns 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
.