- chrono[meta header]
- std::chrono[meta namespace]
- function template[meta id-type]
- cpp20[meta cpp]
namespace std::chrono {
template <class Rep1, class Period1, class Rep2, class Period2>
requires three_way_comparable<
typename common_type_t<
duration<Rep1, Period1>,
duration<Rep2, Period2>
>::rep
>
constexpr auto
operator<=>(const duration<Rep1, Period1>& lhs,
const duration<Rep2, Period2>& rhs); // (1) C++20
}- common_type_t[link /reference/chrono/common_type.md]
三方比較を行う
2つのdurationの単位を合わせた上で、count()の三方比較を行う。
using ct = common_type<decltype(lhs), decltype(rhs)>::type;
return ct(lhs).count() <=> ct(rhs).count();- common_type[link /reference/type_traits/common_type.md]
- count()[link /reference/chrono/duration/count.md]
#include <cassert>
#include <chrono>
using namespace std::chrono;
int main()
{
assert((seconds{3} <=> seconds{3}) == 0);
assert((seconds{3} <=> milliseconds{3000}) == 0);
}- C++20
- Clang:
- GCC: 10
- Visual C++: ??
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出