Edit: /usr/include/boost/hana/fold_left.hpp (3128B)
/*!
@file
Defines `boost::hana::fold_left`.
@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_FOLD_LEFT_HPP
#define BOOST_HANA_FOLD_LEFT_HPP
#include
#include
#include
#include
#include
#include
#include
BOOST_HANA_NAMESPACE_BEGIN
//! @cond
template
constexpr decltype(auto) fold_left_t::operator()(Xs&& xs, State&& state, F&& f) const {
using S = typename hana::tag_of::type;
using FoldLeft = BOOST_HANA_DISPATCH_IF(fold_left_impl,
hana::Foldable::value
);
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
static_assert(hana::Foldable::value,
"hana::fold_left(xs, state, f) requires 'xs' to be Foldable");
#endif
return FoldLeft::apply(static_cast(xs),
static_cast(state),
static_cast(f));
}
template
constexpr decltype(auto) fold_left_t::operator()(Xs&& xs, F&& f) const {
using S = typename hana::tag_of::type;
using FoldLeft = BOOST_HANA_DISPATCH_IF(fold_left_impl,
hana::Foldable::value
);
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
static_assert(hana::Foldable::value,
"hana::fold_left(xs, f) requires 'xs' to be Foldable");
#endif
return FoldLeft::apply(static_cast(xs), static_cast(f));
}
//! @endcond
namespace detail {
template
struct variadic_foldl1 {
F& f;
State& state;
template
constexpr decltype(auto) operator()(T&& ...t) const {
return detail::variadic::foldl1(
static_cast(f),
static_cast(state),
static_cast(t)...
);
}
};
}
template
struct fold_left_impl> : default_ {
// with state
template
static constexpr decltype(auto) apply(Xs&& xs, S&& s, F&& f) {
return hana::unpack(static_cast(xs),
detail::variadic_foldl1{f, s}
);
}
// without state
template
static constexpr decltype(auto) apply(Xs&& xs, F&& f) {
return hana::unpack(static_cast(xs),
hana::partial(
detail::variadic::foldl1,
static_cast(f)
)
);
}
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_FOLD_LEFT_HPP