[libcxx-commits] [PATCH] D114136: [libc++] Test that our algorithms never copy a user-provided comparator.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 17 21:21:03 PST 2021


Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, nilayvaish, Mordante, zoecarver, jloser, var-const.
Quuxplusone added a project: libc++.
Herald added subscribers: mgrang, kristof.beyls.
Quuxplusone requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: libcxx-commits, sstefan1.
Herald added a reviewer: libc++.

This is not mandated by the standard, so it goes in `libcxx/test/libcxx/`.
It's certainly arguable that the algorithms changed here (`is_heap`, `is_sorted`, `min`, `max`) are harmless and we should just let them copy their comparators once. But at the same time, it's nice to have all our algorithms be 100% consistent and never copy a comparator, not even once.

P.S. — If I find the time, I'll investigate the thing I was talking about way back in D93562 <https://reviews.llvm.org/D93562>, where we change `_Comp_ref` to be a lightweight value type instead of a reference type, and then we never need to pass the explicit argument `<_Comp_ref>` to anything. That would be a vastly more invasive PR, touching all the algorithms; this new test would be the regression-test that we would expect to continue passing even after that invasive change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114136

Files:
  libcxx/include/__algorithm/is_heap.h
  libcxx/include/__algorithm/is_heap_until.h
  libcxx/include/__algorithm/is_sorted.h
  libcxx/include/__algorithm/is_sorted_until.h
  libcxx/include/__algorithm/max.h
  libcxx/include/__algorithm/max_element.h
  libcxx/include/__algorithm/min.h
  libcxx/include/__algorithm/min_element.h
  libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114136.388103.patch
Type: text/x-patch
Size: 17768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211118/98c55973/attachment-0001.bin>


More information about the libcxx-commits mailing list