std::chrono::operator==,<=>(std::chrono::year_month_day_last)
來自 cppreference.com
< cpp | chrono | year month day last
定義於標頭檔案 <chrono> |
||
constexpr bool operator==( const std::chrono::year_month_day_last& x, const std::chrono::year_month_day_last& y ) noexcept; |
(1) | (C++20 起) |
constexpr std::strong_ordering operator<=>( const std::chrono::year_month_day_last& x, |
(2) | (C++20 起) |
比較兩個 year_month_day_last
值 x 和 y。這是一個字典序比較:首先比較 year()
,然後比較 month()
。
<
、<=
、>
、>=
和 !=
運算子分別從 operator<=> 和 operator== 合成。
[編輯] 返回值
1) x.year() == y.year() && x.month() == y.month()
2) x.year() <=> y.year() != 0 ? x.year() <=> y.year() : x.month() <=> y.month()
[編輯] 注意
如果 x 和 y 都表示有效日期(x.ok() && y.ok() == true),則字典序比較的結果與日曆順序一致。
[編輯] 示例
執行此程式碼
#include <cassert> #include <chrono> #include <iostream> int main() { auto ymdl1{11/std::chrono::last/2020}; auto mdl{std::chrono::last/std::chrono::November}; auto ymdl2{mdl/2020}; assert(ymdl1 == ymdl2); ymdl1 -= std::chrono::months{2}; ymdl2 -= std::chrono::months{1}; assert(ymdl1 < ymdl2); }