RFR: 8319117: GrowableArray: Allow for custom initializer instead of copy constructor [v12]
Johan Sjölen
jsjolen at openjdk.org
Mon Nov 6 16:48:11 UTC 2023
On Mon, 6 Nov 2023 16:41:22 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:
>> Hi,
>>
>> When using at_put and at_put_grow you can provide a value which will be supplied to the constructor of each element. In other words, you can intialize each element through a copy constructor.
>>
>> I suggest that we also provide a function equivalent where the function is provided a pointer to the memory to be initialized. This can be used for `NONCOPYABLE` classes, for example.
>>
>> This is implemented using a SFINAE pattern because `nullptr` introduces ambiguity if you use static overload.
>>
>> Currently running tier1-tier4.
>
> Johan Sjölen has updated the pull request incrementally with one additional commit since the last revision:
>
> Another test
Hi,
I've reworked this PR a bit. I've introduced two new methods with a `_with` suffix (any ideas for better names?). These methods allow for supplying a functor/lambda for constructing the object, similar to what was in my original PR. The original API now uses these two methods. There are also new tests, along with a toy example showing how this new API could be useful. The `at_put_grow_with` lambda takes two arguments, the latter being a boolean flag indicating whether or not this is the last element. It's perhaps not the most elegant, but I don't think having two templates would do us any good here.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16409#issuecomment-1795452779
More information about the hotspot-dev
mailing list