#ifndef PYTHONIC_INCLUDE_BUILTIN_REDUCE_HPP #define PYTHONIC_INCLUDE_BUILTIN_REDUCE_HPP #include "pythonic/include/utils/functor.hpp" #include #include PYTHONIC_NS_BEGIN namespace builtins { template auto reduce(Operator op, Iterable s) -> decltype(op(std::declval::value_type>(), std::declval::value_type>())); // this convoluted expression computes the fixed-point type of the output // it's required because, e.g. static_list + static_list // returns array // and this widens to list template using reduce_helper_t = typename __combined< T, decltype(std::declval()( std::declval(), std::declval::value_type>()))>::type; template auto reduce(Operator op, Iterable s, T const &init) -> decltype(std::accumulate( s.begin(), s.end(), static_cast>(init), op)); DEFINE_FUNCTOR(pythonic::builtins, reduce); } PYTHONIC_NS_END #endif