mod.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*!
  2. @file
  3. Forward declares `boost::hana::mod`.
  4. Copyright Louis Dionne 2013-2022
  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_MOD_HPP
  9. #define BOOST_HANA_FWD_MOD_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. namespace boost { namespace hana {
  13. //! Generalized integer modulus.
  14. //! @ingroup group-EuclideanRing
  15. //!
  16. //! Given two elements of an EuclideanRing `x` and `y`, with `y`
  17. //! nonzero, `mod` returns the modulus of the division of `x` by `y`.
  18. //! In other words, `mod` can be seen as an equivalent to `%`.
  19. //!
  20. //! Cross-type version of the method
  21. //! --------------------------------
  22. //! The `mod` method is "overloaded" to handle distinct data types
  23. //! with certain properties. Specifically, `mod` 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 `EuclideanRing`s when taken individually
  28. //! 3. `to<C> : A -> B` and `to<C> : B -> C` are `Ring`-embeddings, as
  29. //! determined by the `is_embedding` metafunction.
  30. //!
  31. //! In that case, `mod` is defined as
  32. //! @code
  33. //! mod(x, y) = mod(to<C>(x), to<C>(y))
  34. //! @endcode
  35. //!
  36. //!
  37. //! Example
  38. //! -------
  39. //! @include example/mod.cpp
  40. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  41. constexpr auto mod = [](auto&& x, auto&& y) -> decltype(auto) {
  42. return tag-dispatched;
  43. };
  44. #else
  45. template <typename T, typename U, typename = void>
  46. struct mod_impl : mod_impl<T, U, when<true>> { };
  47. struct mod_t {
  48. template <typename X, typename Y>
  49. constexpr decltype(auto) operator()(X&& x, Y&& y) const;
  50. };
  51. BOOST_HANA_INLINE_VARIABLE constexpr mod_t mod{};
  52. #endif
  53. }} // end namespace boost::hana
  54. #endif // !BOOST_HANA_FWD_MOD_HPP