首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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次检查lhsrhs是相等的,即两种持续时间相同的类型的滴答数是相等的。

3-6%29比较lhsrhs,即比较两种持续时间共同的类型的滴答数。

参数

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)...

二次

代码语言:javascript
复制
#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";
 
}

二次

产出:

二次

代码语言:javascript
复制
2 s == 2000 ms
61 s > 1 min

二次

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com