[libcxx-commits] [PATCH] D131395: [libc++] Implement `lexicographical_compare_three_way`
Adrian Vogelsgesang via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Nov 19 19:57:13 PST 2022
avogelsgesang added inline comments.
================
Comment at: libcxx/test/support/test_comparisons.h:253
+ friend std::partial_ordering operator<=>(PartialComp, PartialComp) = default;
+};
+#endif
----------------
Mordante wrote:
> avogelsgesang wrote:
> > mumbleskates wrote:
> > > avogelsgesang wrote:
> > > > Mordante wrote:
> > > > > Why not complete the set with `std::strong_ordering`?
> > > > because for `strong_ordering` you can simply use a plain `int`. Or should I still add it for completeness?
> > > honestly you could probably just write `using StrongComp = int;`.
> > >
> > > in the tests i've written so far i have used integral types for strong, floating points for partial, and only used structs for weak orderings.
> > >
> > > to that end, it would be useful if PartialComp had an avenue to actually return `partial_ordering::unordered`. you could keep its member typed as an `int` and use `INT_MIN` as a sentinel for the unordered value, which could even allow us to test heterogenous orderable/unorderable values `constexpr` in gcc (which currently(?) does not allow comparing infinities and NaNs against different values in constant evaluation).
> > >
> > > For additional completeness here we would add a `UserComp` struct whose `operator<=>` returns a `UserOrdering` typed value that implements the appropriate operators against literal zero; such types are useful for SFINAE testing and types that utilize `synth-three-way`.
> > > complete the set with `std::strong_ordering`
> >
> > done
> >
> > > `PartialComp` had an avenue to actually return `partial_ordering::unordered`
> >
> > done
> >
> > > `UserComp` struct whose `operator<=>` returns a `UserOrdering`
> >
> > Added. But now gcc-11 crashes
> GCC-12 too? We don't officially support GCC-11 anymore.
Didn't try gcc-12, yet. But I am currently struggling to even get it working for clang.
https://godbolt.org/z/TKj18bqr8 shows my current progress. The problem is that I can't get it to satisfy the `std::three_way_comparable`. `three_way_comparable` requires `same_as<common_comparison_category_t<user_ordering, partial_ordering>, partial_ordering>`, but looking at the implementation of `common_comparison_category_t`, it seems to be hardcoded to `{partial,weak,strong}_ordering` and I don't see a way how to extend it.
As such, I would say: Any type of user-defined ordering is currently not implementable.
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