std::chrono:: operator==,<=> (std::chrono::year_month_day)
|
定义于头文件
<chrono>
|
||
|
constexpr
bool
operator
==
(
const
std::
chrono
::
year_month_day
&
x,
const std:: chrono :: year_month_day & y ) noexcept ; |
(1) | (C++20 起) |
|
constexpr
std::
strong_ordering
operator
<=>
(
const
std::
chrono
::
year_month_day
&
x,
|
(2) | (C++20 起) |
比较两个
year_month_day
值
x
和
y
。这是字典序比较:先比较
year()
,再比较
month()
,最后比较
day()
。
<
、
<=
、
>
、
>=
和
!=
运算符分别由
operator
<=>
和
operator
==
合成。
返回值
注释
如果 x 和 y 均表示有效日期( x. ok ( ) && y. ok ( ) == true ),则字典序比较的结果与日历顺序一致。
示例
#include <chrono> int main() { constexpr auto ymd1{std::chrono::day(13)/7/1337}; constexpr auto ymd2{std::chrono::year(1337)/7/13}; static_assert(ymd1 == ymd2); static_assert(ymd1 <= ymd2); static_assert(ymd1 >= ymd2); static_assert(ymd1 <=> ymd2 == 0); }