[libcxx-commits] [PATCH] D105795: [libcxx][algorithms] adds ranges::lower_bound and ranges::upper_bound

Michael Schellenberger Costa via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 23 03:34:24 PDT 2021


miscco added inline comments.


================
Comment at: libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/ranges_lower_bound/ranges_lower_bound.pass.cpp:84
+    auto proj_ref = std::ref(proj);
+    auto iterator_result = ranges::lower_bound(input.begin(), input.end(), static_cast<T>(-5), comp_ref, proj_ref);
+    assert(iterator_result == ranges::next(input.begin(), 5));
----------------
ldionne wrote:
> Here and elsewhere, please make sure you assign the result of `lower_bound` to a variable with a proper type. In the tests, it's useful to pin down the type of things to test that we return the right types (whereas I would agree in normal code `auto` improves readability).
Actually that would be a bit harmfull due to implicit conversions.

You should assign to auto and then check the type of the variable via a static assert.

With concepts you could also do a `same_as<expected_type> auto it = ...`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105795



More information about the libcxx-commits mailing list