div.hpp 1.7 KB

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