not_equal.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*!
  2. @file
  3. Defines `boost::hana::not_equal`.
  4. Copyright Louis Dionne 2013-2022
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_NOT_EQUAL_HPP
  9. #define BOOST_HANA_NOT_EQUAL_HPP
  10. #include <boost/hana/fwd/not_equal.hpp>
  11. #include <boost/hana/concept/comparable.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/to.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/detail/has_common_embedding.hpp>
  16. #include <boost/hana/detail/nested_to.hpp> // required by fwd decl
  17. #include <boost/hana/equal.hpp>
  18. #include <boost/hana/not.hpp>
  19. namespace boost { namespace hana {
  20. //! @cond
  21. template <typename X, typename Y>
  22. constexpr auto not_equal_t::operator()(X&& x, Y&& y) const {
  23. using T = typename hana::tag_of<X>::type;
  24. using U = typename hana::tag_of<Y>::type;
  25. using NotEqual = not_equal_impl<T, U>;
  26. return NotEqual::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
  27. }
  28. //! @endcond
  29. template <typename T, typename U, bool condition>
  30. struct not_equal_impl<T, U, when<condition>> : default_ {
  31. template <typename X, typename Y>
  32. static constexpr decltype(auto) apply(X&& x, Y&& y) {
  33. return hana::not_(hana::equal(static_cast<X&&>(x),
  34. static_cast<Y&&>(y)));
  35. }
  36. };
  37. // Cross-type overload
  38. template <typename T, typename U>
  39. struct not_equal_impl<T, U, when<
  40. detail::has_nontrivial_common_embedding<Comparable, T, U>::value
  41. >> {
  42. using C = typename hana::common<T, U>::type;
  43. template <typename X, typename Y>
  44. static constexpr decltype(auto) apply(X&& x, Y&& y) {
  45. return hana::not_equal(hana::to<C>(static_cast<X&&>(x)),
  46. hana::to<C>(static_cast<Y&&>(y)));
  47. }
  48. };
  49. }} // end namespace boost::hana
  50. #endif // !BOOST_HANA_NOT_EQUAL_HPP