名稱空間
變體
操作

operator==,!=,<,<=,>,>=,<=>(std::chrono::time_point)

來自 cppreference.com
< cpp‎ | chrono‎ | time_point
 
 
 
 
定義於標頭檔案 <chrono>
(1)
template< class Clock, class Dur1, class Dur2 >

bool operator==( const std::chrono::time_point<Clock,Dur1>& lhs,

                 const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator==( const std::chrono::time_point<Clock,Dur1>& lhs,

                           const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
(2)
template< class Clock, class Dur1, class Dur2 >

bool operator!=( const std::chrono::time_point<Clock,Dur1>& lhs,

                 const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator!=( const std::chrono::time_point<Clock,Dur1>& lhs,

                           const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
(C++20 前)
(3)
template< class Clock, class Dur1, class Dur2 >

bool operator<( const std::chrono::time_point<Clock,Dur1>& lhs,

                const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator<( const std::chrono::time_point<Clock,Dur1>& lhs,

                          const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
(4)
template< class Clock, class Dur1, class Dur2 >

bool operator<=( const std::chrono::time_point<Clock,Dur1>& lhs,

                 const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator<=( const std::chrono::time_point<Clock,Dur1>& lhs,

                           const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
(5)
template< class Clock, class Dur1, class Dur2 >

bool operator>( const std::chrono::time_point<Clock,Dur1>& lhs,

                const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator>( const std::chrono::time_point<Clock,Dur1>& lhs,

                          const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
(6)
template< class Clock, class Dur1, class Dur2 >

bool operator>=( const std::chrono::time_point<Clock,Dur1>& lhs,

                 const std::chrono::time_point<Clock,Dur2>& rhs );
(C++11 起)
(until C++14)
template< class Clock, class Dur1, class Dur2 >

constexpr bool operator>=( const std::chrono::time_point<Clock,Dur1>& lhs,

                           const std::chrono::time_point<Clock,Dur2>& rhs );
(C++14 起)
template< class Clock, class Dur1, std::three_way_comparable_with<Dur1> Dur2 >

constexpr auto operator<=>( const std::chrono::time_point<Clock,Dur1>& lhs,

                            const std::chrono::time_point<Clock,Dur2>& rhs );
(7) (C++20 起)

比較兩個時間點。比較是透過比較時間點的 time_since_epoch() 結果完成的。

1,2) 檢查時間點 lhsrhs 是否引用給定時間戳的同一時間點。
3-6) 比較時間點 lhsrhs
7) 比較時間點 lhsrhs。返回型別從 lhs.time_since_epoch() <=> rhs.time_since_epoch() 推導,因此是 Dur1Dur2 的三向比較結果型別。

!= 運算子由 operator== 合成

(C++20 起)

目錄

[編輯] 引數

lhs, rhs - 要比較的時間點

[編輯] 返回值

1) 如果 lhsrhs 引用同一時間點,則為 true,否則為 false
2) 如果 lhsrhs 引用不同時間點,則為 true,否則為 false
3) 如果 lhs 引用時間點在 rhs 之前,則為 true,否則為 false
4) 如果 lhs 引用時間點在 rhs 之前,或與 rhs 相同,則為 true,否則為 false
5) 如果 lhs 引用時間點在 rhs 之後,則為 true,否則為 false
6) 如果 lhs 引用時間點在 rhs 之後,或與 rhs 相同,則為 true,否則為 false
7) lhs.time_since_epoch() <=> rhs.time_since_epoch()

[編輯] 異常

可能丟擲實現定義的異常。

[編輯] 注意

在 C++11 中,time_point 的雙向比較運算子不是 constexpr,這在 C++14 中得到了糾正。