1 /*!
2 @file
3 Forward declares `boost::hana::product`.
4 
5 @copyright Louis Dionne 2013-2016
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_PRODUCT_HPP
11 #define BOOST_HANA_FWD_PRODUCT_HPP
12 
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/fwd/integral_constant.hpp>
16 
17 
18 BOOST_HANA_NAMESPACE_BEGIN
19     //! Compute the product of the numbers of a structure.
20     //! @ingroup group-Foldable
21     //!
22     //! More generally, `product` will take any foldable structure containing
23     //! objects forming a Ring and reduce them using the Ring's binary
24     //! operation. The initial state for folding is the identity of the
25     //! Ring's operation. It is sometimes necessary to specify the Ring to
26     //! use; this is possible by using `product<R>`. If no Ring is specified,
27     //! the structure will use the Ring formed by the elements it contains
28     //! (if it knows it), or `integral_constant_tag<int>` otherwise.
29     //! Hence,
30     //! @code
31     //!     product<R>(xs) = fold_left(xs, one<R or inferred Ring>(), mult)
32     //!     product<> = product<integral_constant_tag<int>>
33     //! @endcode
34     //!
35     //! For numbers, this will just compute the product of the numbers in the
36     //! `xs` structure.
37     //!
38     //! @note
39     //! The elements of the structure are not actually required to be in the
40     //! same Ring, but it must be possible to perform `mult` on any two
41     //! adjacent elements of the structure, which requires each pair of
42     //! adjacent element to at least have a common Ring embedding. The
43     //! meaning of "adjacent" as used here is that two elements of the
44     //! structure `x` and `y` are adjacent if and only if they are adjacent
45     //! in the linearization of that structure, as documented by the Iterable
46     //! concept.
47     //!
48     //! @note
49     //! See the documentation for `sum` to understand why the Ring must
50     //! sometimes be specified explicitly.
51     //!
52     //!
53     //! Example
54     //! -------
55     //! @include example/product.cpp
56 #ifdef BOOST_HANA_DOXYGEN_INVOKED
57     constexpr auto product = see documentation;
58 #else
59     template <typename T, typename = void>
60     struct product_impl : product_impl<T, when<true>> { };
61 
62     template <typename R>
63     struct product_t;
64 
65     template <typename R = integral_constant_tag<int>>
66     constexpr product_t<R> product{};
67 #endif
68 BOOST_HANA_NAMESPACE_END
69 
70 #endif // !BOOST_HANA_FWD_PRODUCT_HPP
71