comparing.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*!
  2. @file
  3. Defines `boost::hana::comparing`.
  4. @copyright Louis Dionne 2013-2017
  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_COMPARING_HPP
  9. #define BOOST_HANA_COMPARING_HPP
  10. #include <boost/hana/fwd/comparing.hpp>
  11. #include <boost/hana/config.hpp>
  12. #include <boost/hana/detail/decay.hpp>
  13. #include <boost/hana/equal.hpp>
  14. BOOST_HANA_NAMESPACE_BEGIN
  15. namespace detail {
  16. template <typename F>
  17. struct equal_by {
  18. F f;
  19. template <typename X, typename Y>
  20. constexpr auto operator()(X&& x, Y&& y) const&
  21. { return hana::equal(f(static_cast<X&&>(x)), f(static_cast<Y&&>(y))); }
  22. template <typename X, typename Y>
  23. constexpr auto operator()(X&& x, Y&& y) &
  24. { return hana::equal(f(static_cast<X&&>(x)), f(static_cast<Y&&>(y))); }
  25. };
  26. }
  27. //! @cond
  28. template <typename F>
  29. constexpr auto comparing_t::operator()(F&& f) const {
  30. return detail::equal_by<typename detail::decay<F>::type>{static_cast<F&&>(f)};
  31. }
  32. //! @endcond
  33. BOOST_HANA_NAMESPACE_END
  34. #endif // !BOOST_HANA_COMPARING_HPP