equal.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*!
  2. @file
  3. Forward declares `boost::hana::equal`.
  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_EQUAL_HPP
  9. #define BOOST_HANA_FWD_EQUAL_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. #include <boost/hana/detail/nested_to_fwd.hpp>
  13. BOOST_HANA_NAMESPACE_BEGIN
  14. //! Returns a `Logical` representing whether `x` is equal to `y`.
  15. //! @ingroup group-Comparable
  16. //!
  17. //! The `equal` function can be called in two different ways. First, it
  18. //! can be called like a normal function:
  19. //! @code
  20. //! equal(x, y)
  21. //! @endcode
  22. //!
  23. //! However, it may also be partially applied to an argument by using
  24. //! `equal.to`:
  25. //! @code
  26. //! equal.to(x)(y) == equal(x, y)
  27. //! @endcode
  28. //!
  29. //! In other words, `equal.to(x)` is a function object that is equivalent
  30. //! to `partial(equal, x)`. This is provided to enhance the readability of
  31. //! some constructs, especially when using higher order algorithms.
  32. //!
  33. //!
  34. //! Signature
  35. //! ---------
  36. //! Given a Logical `Bool` and two Comparables `A` and `B` that
  37. //! share a common embedding, the signature is
  38. //! @f$ \mathtt{equal} : A \times B \to Bool @f$.
  39. //!
  40. //! @param x, y
  41. //! Two objects to compare for equality.
  42. //!
  43. //!
  44. //! Example
  45. //! -------
  46. //! @include example/equal.cpp
  47. //!
  48. //!
  49. //! > #### Rationale for the arity of `equal`
  50. //! > It is a valid question whether `equal` should accept more than 2
  51. //! > arguments and have semantics matching those of Python's `==`. This
  52. //! > is not supported right now for the following reasons:
  53. //! > - It was implemented in the MPL11, but it was not shown to be useful
  54. //! > so far.
  55. //! > - It does not make sense for `not_equal` to have an arity of more
  56. //! > than 2, only `equal` could maybe have those semantics, which would
  57. //! > break symmetry.
  58. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  59. constexpr auto equal = [](auto&& x, auto&& y) {
  60. return tag-dispatched;
  61. };
  62. #else
  63. template <typename T, typename U, typename = void>
  64. struct equal_impl : equal_impl<T, U, when<true>> { };
  65. struct equal_t : detail::nested_to<equal_t> {
  66. template <typename X, typename Y>
  67. constexpr auto operator()(X&& x, Y&& y) const;
  68. };
  69. constexpr equal_t equal{};
  70. #endif
  71. BOOST_HANA_NAMESPACE_END
  72. #endif // !BOOST_HANA_FWD_EQUAL_HPP