Skip to content

Simplify template logic in Compare.h and add float (epsilon) equality #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ianfixes opened this issue Feb 5, 2018 · 1 comment
Closed
Labels
enhancement New feature or request unittest libs The assert / assure / unittest reporting apparatus is affected

Comments

@ianfixes
Copy link
Collaborator

ianfixes commented Feb 5, 2018

https://stackoverflow.com/questions/41386688/template-specialisation-with-enable-if-and-is-arithmetic-for-a-class

I'm clearly not quite there with the following

#include <limits>

template <typename A = std::enable_if<std::is_integral<AA>::value, AA>::type, typename B = std::enable_if<std::is_integral<BB>::value, BB>::type> struct Compare<A, B>
{
  inline static int between(const A &a,const B &b)
  {
    if (a<b) return -1;
    if (b<a) return  1;
    return 0;
  } // between
  inline static bool equal(const A &a,const B &b)
  {
    if (std::numeric_limits<A>::is_exact && std::numeric_limits<B>::is_exact) return (!(a<b)) && (!(b<a));
    if (std::numeric_limits<A>::epsilon() > std::numeric_limits<B>::epsilon()) {
      return std::numeric_limits<A>::epsilon() > (a > b ? (a - b) : (b - a));
    } else {
      return std::numeric_limits<B>::epsilon() > (a > b ? (a - b) : (b - a));
    }
  } // equal
/* etc
@ianfixes ianfixes added enhancement New feature or request unittest libs The assert / assure / unittest reporting apparatus is affected labels Feb 5, 2018
@ianfixes
Copy link
Collaborator Author

#244 is a better version of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unittest libs The assert / assure / unittest reporting apparatus is affected
Projects
None yet
Development

No branches or pull requests

1 participant