[libcxx-commits] [PATCH] D98983: [libcxx] adds concepts `std::totally_ordered` and `std::totally_ordered_with`

Marek Kurdej via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 20 14:14:38 PDT 2021


curdeius added inline comments.


================
Comment at: libcxx/include/concepts:385
+template<class _Tp>
+concept totally_ordered = equality_comparable<_Tp> && __partially_ordered_with<_Tp, _Tp>;
+
----------------
Using `__partially_ordered_with` here means that the same expression validity is checked twice (e.g. `t < u` and `u < t`, but here the type of t and u is the same, _Tp).
It changes nothing for the correctness (I hope), but may be slightly less efficient.
Would it make sense to split `__partially_ordered_with` into a "one-way" concept, something along these lines (the name is bad):
```
template<class _Tp, class _Up>
concept __oneway_ordered_with =p
  requires(const remove_reference_t<_Tp>& __t, const remove_reference_t<_Up>& __u) {
    { __t <  __u } -> __boolean_testable;
    { __t >  __u } -> __boolean_testable;
    { __t <= __u } -> __boolean_testable;
    { __t >= __u } -> __boolean_testable;
};

template<class _Tp, class _Up>
concept __partially_ordered_with = __oneway_ordered_with<__Tp> && __oneway_ordered_with<__Up>;

template<class _Tp>
concept totally_ordered = equality_comparable<_Tp> && __oneway_ordered_with<_Tp, _Tp>;
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98983/new/

https://reviews.llvm.org/D98983



More information about the libcxx-commits mailing list