relaxed_equal.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015-2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_DETAIL_RELAXED_EQUAL_HPP
  7. #define BOOST_HISTOGRAM_DETAIL_RELAXED_EQUAL_HPP
  8. #include <boost/histogram/detail/priority.hpp>
  9. #include <type_traits>
  10. namespace boost {
  11. namespace histogram {
  12. namespace detail {
  13. struct relaxed_equal {
  14. template <class T, class U>
  15. constexpr auto impl(const T& t, const U& u, priority<1>) const noexcept
  16. -> decltype(t == u) const {
  17. return t == u;
  18. }
  19. // consider T and U not equal, if there is no operator== defined for them
  20. template <class T, class U>
  21. constexpr bool impl(const T&, const U&, priority<0>) const noexcept {
  22. return false;
  23. }
  24. // consider two T equal if they are stateless
  25. template <class T>
  26. constexpr bool impl(const T&, const T&, priority<0>) const noexcept {
  27. return std::is_empty<T>::value;
  28. }
  29. template <class T, class U>
  30. constexpr bool operator()(const T& t, const U& u) const noexcept {
  31. return impl(t, u, priority<1>{});
  32. }
  33. };
  34. } // namespace detail
  35. } // namespace histogram
  36. } // namespace boost
  37. #endif