octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #65244] Simplify code complexity of perms.cc


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #65244] Simplify code complexity of perms.cc
Date: Fri, 9 Feb 2024 10:50:47 -0500 (EST)

Follow-up Comment #14, bug#65244 (group octave):

Ah. Thank you for the example.
My previous tests were with an example that was too simple. (For more complex
examples I didn't understand the assembly.)

Based on your example, would something like this work?

#include <vector>
#include <iostream>

struct octave_value
{
  octave_value ():val(0.0) {}
  explicit octave_value (double d) :val(d){}
  bool is_equal(const octave_value& b)
  {
    return val == b.val;
  }
  
  double val;
};

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>
bool perm ()
{
  std::vector <T> Ar;
  Ar.push_back(T(2.0) );
  Ar.push_back(T(3.0) );

  return is_equal_T<T>(Ar[0], Ar[1]);
}

int main()
{
  if (perm<double>())
    std::cout << "equal double" << std::endl;
  else
    std::cout << "unequal double" << std::endl;
  if (perm<octave_value>())
    std::cout << "equal octave_value" << std::endl;
  else
    std::cout << "unequal octave_value" << std::endl;
}


That might still allow to reduce part of the code duplication in the GetPerms
and GetPermsNoSort templates.

If that works, we should still leave a note about the possible simplification
using constexpr if once we allow C++17.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?65244>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]