/*! @file Defines `boost::hana::sum`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_SUM_HPP #define BOOST_HANA_SUM_HPP #include #include #include #include #include #include #include // required by fwd decl #include #include namespace boost { namespace hana { //! @cond template template constexpr decltype(auto) sum_t::operator()(Xs&& xs) const { using S = typename hana::tag_of::type; using Sum = BOOST_HANA_DISPATCH_IF(sum_impl, hana::Foldable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Monoid::value, "hana::sum requires 'M' to be a Monoid"); static_assert(hana::Foldable::value, "hana::sum(xs) requires 'xs' to be Foldable"); #endif return Sum::template apply(static_cast(xs)); } //! @endcond template struct sum_impl> : default_ { template static constexpr decltype(auto) apply(Xs&& xs) { return hana::fold_left(static_cast(xs), hana::zero(), hana::plus); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_SUM_HPP