名稱空間
變體
操作

std::chrono::is_clock

來自 cppreference.com
< cpp‎ | chrono
 
 
 
定義於標頭檔案 <chrono>
template< class T >
struct is_clock;
(C++20 起)

如果 T 滿足 Clock 的要求,則提供成員常量 value 等於 true。對於任何其他型別,valuefalse

對於此特性,實現確定型別無法滿足 Clock 要求的程度是未指定的,除非最小的 T 不符合 Clock 的條件,除非它滿足以下所有條件:

  • T::rep
  • T::period
  • T::duration
  • T::time_point
  • T::is_steady
  • T::now()

如果程式為 std::is_clockstd::is_clock_v 新增特化,則行為是未定義的。

目錄

[編輯] 模板引數

T - 要檢查的型別

[編輯] 輔助變數模板

template< class T >
constexpr bool is_clock_v = is_clock<T>::value;
(C++20 起)

繼承自 std::integral_constant

成員常量

value
[靜態]
如果 T 滿足 Clock 要求,則為 true,否則為 false
(public static 成員常量)

成員函式

operator bool
將物件轉換為 bool,返回 value
(公開成員函式)
operator()
(C++14)
返回 value
(公開成員函式)

成員型別

型別 定義
value_type bool
型別 std::integral_constant<bool, value>

[編輯] 可能的實現

template<class>
struct is_clock : std::false_type {};
 
template<class T>
    requires
        requires
        {
            typename T::rep;
            typename T::period;
            typename T::duration;
            typename T::time_point;
            T::is_steady; // type is not checked
            T::now();     // return type is not checked
        }
struct is_clock<T> : std::true_type {};

[編輯] 注意

如果 T 滿足 Clock 的其他要求,但 T::is_steady 不是 const bool 型別,或者 T::now() 不是 T::time_point 型別,則 is_clock_v<T> 的結果是未指定的。

[編輯] 示例

#include <chrono>
#include <ratio>
 
static_assert
(
    std::chrono::is_clock_v<std::chrono::utc_clock> and
    not std::chrono::is_clock_v<std::chrono::duration<int, std::exa>>
);
 
int main() {}