RFR: 8367536: Change RBTree to use C++17 features [v2]
Kim Barrett
kbarrett at openjdk.org
Tue Sep 16 06:24:12 UTC 2025
On Fri, 12 Sep 2025 15:01:36 GMT, Casper Norrbin <cnorrbin at openjdk.org> wrote:
>> Hi everyone,
>>
>> C++17 lets us tidy up som of the ugly templating done in the red-black tree. We can replace the `std::false_type`/`std::true_type` tricks used to discover comparator and verifier signatures with the new `std::is_invocable(_r_v)`, and most of the overload/SFINAE noise can disappear thanks to `if constexpr`.
>>
>> We can now write one-liners such as:
>> ```c++
>> static constexpr bool HasKeyComparator = std::is_invocable_r_v<RBTreeOrdering, decltype(&CMP::cmp), K, K>;
>>
>>
>> and then select the right branch with
>> ```c++
>> if constexpr (HasKeyComparator<CMP>) { }
>>
>> inside a single function instead of having several `ENABLE_IF` overloads.
>>
>> This results in fewer lines, clearer intent, and more readable errors, while keeping behaviour identical.
>>
>> Testing:
>> - Oracle tiers 1-3
>
> Casper Norrbin has updated the pull request incrementally with one additional commit since the last revision:
>
> removed unneeded CMP templates
Looks good.
src/hotspot/share/utilities/rbTree.hpp line 201:
> 199: template <typename CMP>
> 200: static constexpr bool HasKeyComparator =
> 201: std::is_invocable_r_v<RBTreeOrdering, decltype(&CMP::cmp), K, K>;
Note that these are static data member templates, which were not permitted by the style
guide until about an hour ago. :)
-------------
Marked as reviewed by kbarrett (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/27260#pullrequestreview-3227581496
PR Review Comment: https://git.openjdk.org/jdk/pull/27260#discussion_r2350967857
More information about the hotspot-dev
mailing list