std::chrono::operator==,<=>(std::chrono::day)

来自cppreference.com
< cpp‎ | chrono‎ | day
 
 
 
 
在标头 <chrono> 定义
constexpr bool operator==( const std::chrono::day& x,
                           const std::chrono::day& y ) noexcept;
(1) (C++20 起)
constexpr std::strong_ordering operator<=>( const std::chrono::day& x,
                                            const std::chrono::day& y ) noexcept;
(2) (C++20 起)

比较二个 std::chrono::day xy

<<=>>=!= 运算符分别从 operator<=>operator== 合成

返回值

1) unsigned(x) == unsigned(y)
2) unsigned(x) <=> unsigned(y)

示例

#include <iostream>
#include <chrono>
 
int main()
{
    std::chrono::day d1{15};
    std::chrono::day d2{20};
 
    d1 == d2 ? std::cout << "d1 and d2 are equal\n"
             : std::cout << "d1 and d2 are not equal\n";
 
    using namespace std::literals::chrono_literals;
 
    std::cout << std::boolalpha
              << (6d < 9d) << ' ' << (6d == 6d) << ' ' << (6d <= 9d) << ' '
              << (9d > 6d) << ' ' << (9d != 6d) << ' ' << (9d >= 6d) << '\n';
}

输出:

d1 and d2 are not equal
true true true true true true