Mercurial > octave
changeset 33466:65cbf92800ed
Use C++17 feature constexpr to simplify perms.cc (bug #65645).
* libinterp/corefcn/perms.cc (GetPerms): Use constexpr instead of is_equal_T.
Remove the is_equal_T templates and specializations that are no longer
necessary. Remove obsolete FIXME comment.
author | Hendrik Koerner <koerhen@web.de> |
---|---|
date | Fri, 26 Apr 2024 13:08:25 +0800 |
parents | 1467d8d5e6d3 |
children | c51b07a71421 |
files | libinterp/corefcn/perms.cc |
diffstat | 1 files changed, 7 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/perms.cc Fri Apr 26 15:10:15 2024 +0200 +++ b/libinterp/corefcn/perms.cc Fri Apr 26 13:08:25 2024 +0800 @@ -50,30 +50,6 @@ // Use C++ template to cater for the different octave array classes. // -// FIXME: To allow comparison between all supported template types, we need -// to use either "if constexpr" (supported in C++17) or template specialisation -// (supported in C++11). Currently (2024), Octave stipulates the usage of -// C++11, so the (slightly more complex) template specialization is used. -// Once Octave moves to C++17 or beyond, the following code snippet is -// preferrable and the comparison templates can be removed: -// bool isequal; -// if constexpr (std::is_same<T, octave_value>::value) -// isequal = Ar[i].is_equal (Ar[j]); -// else -// isequal = (Ar[i] == Ar[j]); - -template <typename T> -bool is_equal_T (T a, T b) -{ - return a == b; -} - -template <> -bool is_equal_T<octave_value> (octave_value a, octave_value b) -{ - return a.is_equal (b); -} - template <typename T> static inline Array<T> GetPerms (const Array<T>& ar_in, bool uniq_v = false) @@ -105,7 +81,13 @@ { for (octave_idx_type j = i + 1; j < m; j++) { - bool isequal = is_equal_T<T> (Ar[i], Ar[j]); + bool isequal; + if constexpr (std::is_same<T, octave_value>::value) + // operator '==' is not supported for octave_value objects + isequal = Ar[i].is_equal (Ar[j]); + else + isequal = (Ar[i] == Ar[j]); + if (myvidx[j] > myvidx[i] && isequal) { myvidx[j] = myvidx[i]; // not yet processed...