• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2 @file
3 Forward declares `boost::hana::mod`.
4 
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8  */
9 
10 #ifndef BOOST_HANA_FWD_MOD_HPP
11 #define BOOST_HANA_FWD_MOD_HPP
12 
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 
16 
17 BOOST_HANA_NAMESPACE_BEGIN
18     //! Generalized integer modulus.
19     //! @ingroup group-EuclideanRing
20     //!
21     //! Given two elements of an EuclideanRing `x` and `y`, with `y`
22     //! nonzero, `mod` returns the modulus of the division of `x` by `y`.
23     //! In other words, `mod` can be seen as an equivalent to `%`.
24     //!
25     //! Cross-type version of the method
26     //! --------------------------------
27     //! The `mod` method is "overloaded" to handle distinct data types
28     //! with certain properties. Specifically, `mod` is defined for
29     //! _distinct_ data types `A` and `B` such that
30     //! 1. `A` and `B` share a common data type `C`, as determined by the
31     //!    `common` metafunction
32     //! 2. `A`, `B` and `C` are all `EuclideanRing`s when taken individually
33     //! 3. `to<C> : A -> B` and `to<C> : B -> C` are `Ring`-embeddings, as
34     //!    determined by the `is_embedding` metafunction.
35     //!
36     //! In that case, `mod` is defined as
37     //! @code
38     //!     mod(x, y) = mod(to<C>(x), to<C>(y))
39     //! @endcode
40     //!
41     //!
42     //! Example
43     //! -------
44     //! @include example/mod.cpp
45 #ifdef BOOST_HANA_DOXYGEN_INVOKED
46     constexpr auto mod = [](auto&& x, auto&& y) -> decltype(auto) {
47         return tag-dispatched;
48     };
49 #else
50     template <typename T, typename U, typename = void>
51     struct mod_impl : mod_impl<T, U, when<true>> { };
52 
53     struct mod_t {
54         template <typename X, typename Y>
55         constexpr decltype(auto) operator()(X&& x, Y&& y) const;
56     };
57 
58     constexpr mod_t mod{};
59 #endif
60 BOOST_HANA_NAMESPACE_END
61 
62 #endif // !BOOST_HANA_FWD_MOD_HPP
63