plus.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. @file
  3. Forward declares `boost::hana::plus`.
  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_PLUS_HPP
  9. #define BOOST_HANA_FWD_PLUS_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Associative binary operation on a `Monoid`.
  14. //! @ingroup group-Monoid
  15. //!
  16. //! @param x, y
  17. //! Two objects to combine with the `Monoid`'s binary operation.
  18. //!
  19. //!
  20. //! Cross-type version of the method
  21. //! --------------------------------
  22. //! The `plus` method is "overloaded" to handle distinct data types
  23. //! with certain properties. Specifically, `plus` is defined for
  24. //! _distinct_ data types `A` and `B` such that
  25. //! 1. `A` and `B` share a common data type `C`, as determined by the
  26. //! `common` metafunction
  27. //! 2. `A`, `B` and `C` are all `Monoid`s when taken individually
  28. //! 3. `to<C> : A -> B` and `to<C> : B -> C` are `Monoid`-embeddings, as
  29. //! determined by the `is_embedding` metafunction.
  30. //!
  31. //! The definition of `plus` for data types satisfying the above
  32. //! properties is obtained by setting
  33. //! @code
  34. //! plus(x, y) = plus(to<C>(x), to<C>(y))
  35. //! @endcode
  36. //!
  37. //!
  38. //! Example
  39. //! -------
  40. //! @include example/plus.cpp
  41. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  42. constexpr auto plus = [](auto&& x, auto&& y) -> decltype(auto) {
  43. return tag-dispatched;
  44. };
  45. #else
  46. template <typename T, typename U, typename = void>
  47. struct plus_impl : plus_impl<T, U, when<true>> { };
  48. struct plus_t {
  49. template <typename X, typename Y>
  50. constexpr decltype(auto) operator()(X&& x, Y&& y) const;
  51. };
  52. constexpr plus_t plus{};
  53. #endif
  54. BOOST_HANA_NAMESPACE_END
  55. #endif // !BOOST_HANA_FWD_PLUS_HPP