命名空间
变体
操作

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

来自 cppreference.cn
< 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 起)
(直到 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 起)
(直到 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 起)
(直到 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 起)
(直到 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 起)
(直到 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 起)
(直到 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().

[编辑] 异常

可能抛出实现定义的异常。

[编辑] 注解

time_point 的双向比较运算符在 C++11 中不是 constexpr,这在 C++14 中得到了修正。