/*! @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 BOOST_HANA_NAMESPACE_BEGIN template struct sum_t { #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Monoid::value, "hana::sum requires 'M' to be a Monoid"); #endif template constexpr decltype(auto) 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::Foldable::value, "hana::sum(xs) requires 'xs' to be Foldable"); #endif return Sum::template apply(static_cast(xs)); } }; template struct sum_impl> : default_ { template static constexpr decltype(auto) apply(Xs&& xs) { return hana::fold_left(static_cast(xs), hana::zero(), hana::plus); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_SUM_HPP