[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 12 13:02:28 PST 2023


avogelsgesang added inline comments.


================
Comment at: libcxx/include/__algorithm/three_way_comp_ref_type.h:39
+  __do_compare_assert(int, _LHS& __l, _RHS& __r, _Order __o)
+    requires __comparison_category<decltype(declval<_Comp&>()(declval<_LHS&>(), declval<_RHS&>()))>
+  {
----------------
var-const wrote:
> Question: do we need this `requires` clause? We only use the class in our internal code, so it seems like we shouldn't need this. If it's to validate the comparator given by the user, then it shouldn't only be done in the debug mode.
The idea is: For comparators which can be called as `cmp(Type1, Type2)` but not as `cmp(Type2, Type1)`, we want to skip this check, and fallback to the other `__do_compare_assert` further down.

I copied this from `__algorithm/comp_ref_type.h`, which had
```
    decltype((void)std::declval<_Compare&>()(
        std::declval<_LHS &>(), std::declval<_RHS &>()))
```
to check whether the parameters can be swapped


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131395



More information about the libcxx-commits mailing list