Integrated: 8367536: Change RBTree to use C++17 features
Casper Norrbin
cnorrbin at openjdk.org
Mon Sep 22 13:00:24 UTC 2025
On Fri, 12 Sep 2025 13:59:51 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
This pull request has now been integrated.
Changeset: 2131584a
Author: Casper Norrbin <cnorrbin at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/2131584add9ab46c3380bbf35170307e4878ce51
Stats: 62 lines in 2 files changed: 7 ins; 23 del; 32 mod
8367536: Change RBTree to use C++17 features
Reviewed-by: kbarrett, ayang
-------------
PR: https://git.openjdk.org/jdk/pull/27260
More information about the hotspot-dev
mailing list