Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:10

0001 /*!
0002 @file
0003 Defines `boost::hana::product`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_PRODUCT_HPP
0011 #define BOOST_HANA_PRODUCT_HPP
0012 
0013 #include <boost/hana/fwd/product.hpp>
0014 
0015 #include <boost/hana/concept/foldable.hpp>
0016 #include <boost/hana/concept/ring.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/fold_left.hpp>
0020 #include <boost/hana/integral_constant.hpp> // required by fwd decl
0021 #include <boost/hana/mult.hpp>
0022 #include <boost/hana/one.hpp>
0023 
0024 
0025 namespace boost { namespace hana {
0026     //! @cond
0027     template <typename R>
0028     template <typename Xs>
0029     constexpr decltype(auto) product_t<R>::operator()(Xs&& xs) const {
0030         using S = typename hana::tag_of<Xs>::type;
0031         using Product = BOOST_HANA_DISPATCH_IF(product_impl<S>,
0032             hana::Foldable<S>::value
0033         );
0034 
0035     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0036         static_assert(hana::Ring<R>::value,
0037         "hana::product<R> requires 'R' to be a Ring");
0038 
0039         static_assert(hana::Foldable<S>::value,
0040         "hana::product<R>(xs) requires 'xs' to be Foldable");
0041     #endif
0042 
0043         return Product::template apply<R>(static_cast<Xs&&>(xs));
0044     }
0045     //! @endcond
0046 
0047     template <typename T, bool condition>
0048     struct product_impl<T, when<condition>> : default_ {
0049         template <typename R, typename Xs>
0050         static constexpr decltype(auto) apply(Xs&& xs) {
0051             return hana::fold_left(static_cast<Xs&&>(xs), hana::one<R>(), hana::mult);
0052         }
0053     };
0054 }} // end namespace boost::hana
0055 
0056 #endif // !BOOST_HANA_PRODUCT_HPP