On Fri, 25 Aug 2023 08:55:29 GMT, Stefan Karlsson <stef...@openjdk.org> wrote:
>> It's arbitrary and chosen by the caller through `f`, so I can't say :-). The >> best use case we have now is when you only have an `int` which uniquely >> describes an `LGRPSpace`. > > This code looks similar to a capturing lambda. Would an alternative be to use > that instead and let the calling code be changed to: > > > int i = lgrp_spaces()->find([](LGRPSpace* space) { > return space->lgrp_id() == lgrp_id; > }); > > > Alternatively: > > auto matches_lgrp_id = [](LGRPSpace* space) { > return space->lgrp_id() == lgrp_id; > }; > > int i = lgrp_spaces()->find(matches_lgrp_id); We could just as well do a capturing lambda here, yes. Then we'd have: ```c++ template<F> int find(F finder); It'd be a template instead of function pointer since it's a capturing lambda and `std::function` is not permitted in Hotspot AFAIK. As an aside, to clarify for readers: There's a `&` missing in the capture list of your examples. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15418#discussion_r1305442361