JDK-8138724 : GrowableArray methods should have the compare function be specified via a function type
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2015-10-01
  • Updated: 2020-02-11
  • Resolved: 2020-02-11
Related Reports
Relates :  
Description
src/share/vm/utilities/growableArray.hpp   
382   template <int compare(E&, E&)> E insert_sorted(E& key) {
392   template <typename K, int compare(K&, E&)> int find_sorted(K& key, bool& found) {

Having the compare function be specified via a function type (e.g. a
non-type template parameter) rather than an argument seems rather
limiting.  More general, and (IMO) easier to use, would be a type
template parameter deduced from an argument, e.g.

template<typename Compare>
E insert_sorted(const E& key, Compare compare) {
 ...
 int location = find_sorted(key, found, compare);
 ...
}

template<typename K, typename Compare>
int find_sorted(const K& key, bool& found, Compare compare) const {
 ...
}

Let
- ga is a GrowableArray<T>
- my_value is an instance f T
- my_compare is a function of type int (*)(const T&, const T&)

Old usage:

 ga.insert_sorted<my_compare>(my_value);
 ga.find_sorted<T, my_compare>(my_value, found);

New usage:

 ga.insert_sorted(my_value, my_compare);
 ga.find_sorted(my_value, found, my_compare);

and new usage also allows the use of function objects, not just
pointers to functions.

Comments
Runtime Triage: This is not on our current list of priorities. We will consider this feature if we receive additional customer requirements.
11-02-2020