operators (std::chrono::duration)
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (1) |  | 
|---|---|---|
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (2) |  | 
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator<(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (3) |  | 
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (4) |  | 
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator>(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (5) |  | 
| template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); | (6) |  | 
比较两个持续时间。
1-2%29次检查lhs和rhs是相等的,即两种持续时间相同的类型的滴答数是相等的。
3-6%29比较lhs到rhs,即比较两种持续时间共同的类型的滴答数。
参数
| lhs | - | duration on the left-hand side of the operator | 
|---|---|---|
| rhs | - | duration on the right-hand side of the operator | 
返回值
假设CT =
std::common_type<std::chrono::duration<Rep1, Period1>,
std::chrono::duration<Rep2, Period2>>::type,然后:
1%29CT(lhs).count() == CT(rhs).count()...
2%29!(lhs == rhs)...
3%29CT(lhs).count() < CT(rhs).count()...
4%29!(rhs < lhs)...
5%29rhs < lhs...
6%29!(lhs < rhs)...
例
二次
#include <chrono>
#include <iostream>
int main()
{
    if(std::chrono::seconds(2) == std::chrono::milliseconds(2000))
        std::cout <<  "2 s == 2000 ms\n";
    else
        std::cout <<  "2 s != 2000 ms\n";
 
    if(std::chrono::seconds(61) > std::chrono::minutes(1))
        std::cout <<  "61 s > 1 min\n";
    else
        std::cout <<  "61 s <= 1 min\n";
 
}二次
产出:
二次
2 s == 2000 ms
61 s > 1 min二次
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

