ordering.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. @file
  3. Forward declares `boost::hana::ordering`.
  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_FWD_ORDERING_HPP
  9. #define BOOST_HANA_FWD_ORDERING_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN
  12. //! Returns a function performing `less` after applying a transformation
  13. //! to both arguments.
  14. //! @ingroup group-Orderable
  15. //!
  16. //! `ordering` creates a total order based on the result of applying a
  17. //! function to some objects, which is especially useful in conjunction
  18. //! with algorithms that accept a custom predicate that must represent
  19. //! a total order.
  20. //!
  21. //! Specifically, `ordering` is such that
  22. //! @code
  23. //! ordering(f) == less ^on^ f
  24. //! @endcode
  25. //! or, equivalently,
  26. //! @code
  27. //! ordering(f)(x, y) == less(f(x), f(y))
  28. //! @endcode
  29. //!
  30. //! @note
  31. //! This is not a tag-dispatched method (hence it can't be customized),
  32. //! but just a convenience function provided with the `Orderable` concept.
  33. //!
  34. //!
  35. //! Signature
  36. //! ---------
  37. //! Given a Logical `Bool` and an Orderable `B`, the signature is
  38. //! @f$ \mathrm{ordering} : (A \to B) \to (A \times A \to Bool) @f$.
  39. //!
  40. //!
  41. //! Example
  42. //! -------
  43. //! @include example/ordering.cpp
  44. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  45. constexpr auto ordering = [](auto&& f) {
  46. return [perfect-capture](auto&& x, auto&& y) -> decltype(auto) {
  47. return less(f(forwarded(x)), f(forwarded(y)));
  48. };
  49. };
  50. #else
  51. struct ordering_t {
  52. template <typename F>
  53. constexpr auto operator()(F&& f) const;
  54. };
  55. constexpr ordering_t ordering{};
  56. #endif
  57. BOOST_HANA_NAMESPACE_END
  58. #endif // !BOOST_HANA_FWD_ORDERING_HPP