[libcxx-commits] [PATCH] D130330: [libc++][NFC] Add checks for lifetime issues in classic algorithms.

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 26 15:41:33 PDT 2022


huixie90 added inline comments.


================
Comment at: libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp:551
+
+  test(simple_in, [&](I b, I e) { std::any_of(b, e, is_neg); });
+  test(simple_in, [&](I b, I e) { std::all_of(b, e, is_neg); });
----------------
Mordante wrote:
> var-const wrote:
> > Mordante wrote:
> > > var-const wrote:
> > > > I don't know of a good way to pass a pointer to a template function, so unlike similar tests for range algorithms I'm using lambdas here.
> > > You mean a pointer to `std::any`?
> > I think using `any` here would prevent running this test in pre-C++17 modes, right? (good idea, though)
> sorry I meant `std::any_of`.
It is fine to use lambda here. it is not easy to pass `std::any_of` because it is 
1. a function template
2. an overload set.

to solve 1, usually you need to explicit specify template arguments. `&my_fun<intput1, input2>`

to solve 2, you need to `static_cast` it to a function pointer.

combining 1 and 2 is lot of code which is not worth it.

I use `BOOST_HOF_LIFT` all the time to lift non-functional-friendly functions to an object that can be passed around but that require Boost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130330



More information about the libcxx-commits mailing list