RFR: 8367536: Change RBTree to use C++17 features [v2]

Casper Norrbin cnorrbin at openjdk.org
Fri Sep 12 15:01:36 UTC 2025


> 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

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27260/files
  - new: https://git.openjdk.org/jdk/pull/27260/files/0c6b03c8..f20fc8e9

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27260&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27260&range=00-01

  Stats: 10 lines in 1 file changed: 0 ins; 3 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/27260.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27260/head:pull/27260

PR: https://git.openjdk.org/jdk/pull/27260


More information about the hotspot-dev mailing list