[libcxx-commits] [PATCH] D117025: [libc++][ranges] Implement ranges::min_element

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 4 13:03:42 PST 2022


philnik added a reviewer: var-const.
philnik marked 7 inline comments as done.
philnik added inline comments.


================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.min.max/ranges.min_element.pass.cpp:127
+
+static_assert(std::is_same_v<std::ranges::dangling, decltype(std::ranges::min_element(std::array<int, 0>{}))>);
+
----------------
Quuxplusone wrote:
> Quuxplusone wrote:
> > Moot: `, 0` is kind of a weird corner case; I'd make this `, 10` or `, 42`.
> > But also, we need to test this behavior outside an unevaluated expression. I suggest
> > ```
> > constexpr void test_dangling()
> > {
> >   int a[] = {2, 1, 3};
> >   int compares = 0;
> >   int projections = 0;
> >   auto comparator = [&](int a, int b) { compares += 1; return a < b; };
> >   auto projection = [&](int a) { projections += 1; return a; };
> >   std::same_as<std::ranges::dangling> auto r =
> >     std::ranges::min_element(r, comparator, projection);
> >   assert(compares == 2);
> >   assert(projections == 4);
> > }
> > ```
> You can remove line 128 (the static_assert) now, which will allow you to remove `#include <array>` (and eliminate the weirdness of `std::array<T, 0>`).
I'm still using `std::array` in line 140.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117025



More information about the libcxx-commits mailing list