operators (std::chrono::duration)
运算符=,%21=,<,<=,>=%28std::chrono::工期%29
template | (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。