operator==,!=,<,<=,>,>=(std::chrono::duration)
提供: cppreference.com
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator==(const std::chrono::duration<Rep1, Period1>& lhs, |
(1) | (C++11以上) |
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator!=(const std::chrono::duration<Rep1, Period1>& lhs, |
(2) | (C++11以上) (C++20未満) |
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator<(const std::chrono::duration<Rep1, Period1>& lhs, |
(3) | (C++11以上) |
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator<=(const std::chrono::duration<Rep1, Period1>& lhs, |
(4) | (C++11以上) |
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator>(const std::chrono::duration<Rep1, Period1>& lhs, |
(5) | (C++11以上) |
template <class Rep1, class Period1, class Rep2, class Period2> constexpr bool operator>=(const std::chrono::duration<Rep1, Period1>& lhs, |
(6) | (C++11以上) |
template <class Rep1, class Period1, class Rep2, class Period2> requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>> |
(7) | (C++20以上) |
2つの duration を比較します。 CT を std::common_type<std::chrono::duration<Rep1, Period1>, std::chrono::duration<Rep2, Period2>>::type とすると:
1-2)
lhs
と rhs
が等しいかどうか調べます。 つまり、両方の duration の共通型に対する刻み数が等しいかどうか調べます。3-6)
lhs
と rhs
を比較します。 つまり、両方の duration の共通型に対する刻み数を比較します。7)
lhs
と rhs
を比較します。 つまり、両方の duration の共通型に対する刻み数を比較します。 戻り値の型は CT(lhs).count() <=> CT(rhs).count() から推定されます。[編集] 引数
lhs | - | 演算子の左側の duration |
rhs | - | 演算子の右側の duration |
[編集] 戻り値
1) CT(lhs).count() == CT(rhs).count()
2) !(lhs == rhs)
3) CT(lhs).count() < CT(rhs).count()
4) !(rhs < lhs)
5) rhs < lhs
6) !(lhs < rhs)
7) CT(lhs).count() <=> CT(rhs).count()
[編集] 例
Run this code
#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