Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1.  
  2. struct DefaultCompare
  3. {
  4.     template<typename T1, typename T2>
  5.     static xht_forceinline std::enable_if_t<
  6.         !(std::is_floating_point_v<T1> && std::is_floating_point_v<T2>),
  7.         bool
  8.     > Compare(const T1& t1, const T2& t2)
  9.     {
  10.         return t1 == t2;
  11.     }
  12.  
  13.     template<typename T1, typename T2>
  14.     static xht_forceinline std::enable_if_t<
  15.         std::is_floating_point_v<T1> && std::is_floating_point_v<T2>,
  16.         bool
  17.     > Compare(const T1& t1, const T2& t2)
  18.     {
  19.         using T3 = std::common_type_t<T1, T2>;
  20.         T3 x = t1;
  21.         T3 y = t2;
  22.         return !memcmp(&x, &y, sizeof(T3));
  23.     }
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement