[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    Re: RFR: 8314502: Change the comparator taking version of GrowableArray::find to be a template metho
From:       Kim Barrett <kbarrett () openjdk ! org>
Date:       2023-10-31 5:16:33
Message-ID: DTpoAyK0TrOtAMbC_kxnPHzz0-PCyHY_4tZW3xBxdUM=.6a7a776a-c5c4-4507-ae1f-911f4eedc6d3 () github ! com
[Download RAW message or body]

On Tue, 31 Oct 2023 00:57:02 GMT, John R Rose <jrose@openjdk.org> wrote:

> > Using a reference here leads to unnecessary overhead when `E` is small and
> > trivially copyable, unless the predicate function is inlined. Pass by value is
> > better in that case. Of course, as noted above, if `E` is "expensive" to copy
> > or non-copyable then a reference is needed. Boost has this thing called
> > `call_traits<E>::param_type` for this issue, but I don't recommend we copy
> > that.
> > 
> > Idiomatic C++ makes the entire function a template parameter, as was suggested
> > earlier in this PR. That dodges this question entirely, leaving the parameter
> > passing decision to the predicate function where it belongs, rather than
> > having it imposed by GrowableArray::find.  The find function just imposes the
> > requirement that the predicate satisfies the appropriate constraints, e.g. it
> > is callable on an element reference and returns convertible to bool.
> 
> I agree we should be using a template-typed function instead of a function pointer \
> here. I think a lot of our uses of function pointers in our code base would work \
> better as template-typed args. See for example the `grow` argument (of template \
> type `GFN`) at this point: \
> https://github.com/openjdk/jdk/blob/d051f22284e7ccc288c658588f73da672d9bfacd/src/hotspot/share/utilities/unsigned5.hpp#L343C34-L343C34
>  
> In that case I cited, if the `grow` argument it were a function pointer instead of \
> a template-typed function-like argument (Kim what's the right term here? \
> "functor"??), then performance and flexibility would be unacceptably harmed. 
> I think the `find` argument is just the same kind of thingy.

"Functor" is a reasonable choice, with plenty of precedent. 

The C++ standard doesn't use the term "functor". Instead it defines (C++14
20.9) the terms "function object type" and associated "function object" to
include all of

(1) pointer to function types
(2) class types with a member operator()
(3) class types with a conversion to pointer to function

The C++ standard doesn't have distinct terminology for cases (2) and (3), so
far as I can tell.

Sometimes people use either "functor" or "function object class" to
distinguish (2) (web search for "C++ functor" for examples of the former).
Sometimes people use "function object" to refer only to (2). So the community
is inconsistent in this respect.

I'm not sure I've ever seen (3).  (Not even in "look at this obscure C++
thing" discussions.)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15418#discussion_r1377062682


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic