std::chrono::operator==,<=>(std::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,
const std::chrono::year_month_day_last& y ) noexcept;
| (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);
}
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/chrono/year_month_day_last/operator_cmp