[libcxx-commits] [PATCH] D100429: [libc++][ranges] Add range.cmp: equal_to, not_equal_to, less, etc.

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 21 10:02:14 PDT 2021


zoecarver added inline comments.


================
Comment at: libcxx/test/support/pointer_comparison_test_helper.h:12
+template <template <class> class CompareTemplate>
+void do_pointer_comparison_test() {
+  typedef CompareTemplate<int*> Compare;
----------------
Quuxplusone wrote:
> tcanens wrote:
> > If you want to test this sort of thing, I'd suggest something like the example from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78420#c0. "Comparison produces a total order when the built-in is required to" (which describes 3/4 of the test cases below) is not a particularly interesting property compared to "comparison produces a total order even when the built-in is not required to".
> How about
> ```
>   struct {
>     int a, b;
>   } local;
>   int *a = &local.a;
>   int *b = &local.b;
>   int *c = nullptr;
>   int *d = &local.a + 1;
>   std::uintptr_t ua = reinterpret_cast<std::uintptr_t>(a);
>   std::uintptr_t ub = reinterpret_cast<std::uintptr_t>(b);
>   std::uintptr_t uc = reinterpret_cast<std::uintptr_t>(c);
>   std::uintptr_t ud = reinterpret_cast<std::uintptr_t>(d);
>   assert(comp(a, a) == ucomp(ua, ua));
>   assert(comp(a, b) == ucomp(ua, ub));
>   assert(comp(a, c) == ucomp(ua, uc));
>   assert(comp(a, d) == ucomp(ua, ud));
>   assert(comp(b, a) == ucomp(ub, ua));
>   assert(comp(b, b) == ucomp(ub, ub));
>   assert(comp(b, c) == ucomp(ub, uc));
>   assert(comp(b, d) == ucomp(ub, ud));
>   assert(comp(c, a) == ucomp(uc, ua));
>   assert(comp(c, b) == ucomp(uc, ub));
>   assert(comp(c, c) == ucomp(uc, uc));
>   assert(comp(c, d) == ucomp(uc, ud));
>   assert(comp(d, a) == ucomp(ud, ua));
>   assert(comp(d, b) == ucomp(ud, ub));
>   assert(comp(d, c) == ucomp(ud, uc));
>   assert(comp(d, d) == ucomp(ud, ud));
> ```
> I haven't thought hard about how to factor out the testing of `std::less<int*>` and `std::less<>` so that you can just call the function template twice with different args instead of repeating that entire 16-line array of tests for `vcomp`.
The loop is back. But in this case, think it both increases coverage and readability. Let me know what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100429



More information about the libcxx-commits mailing list