![]() |
Home | Libraries | People | FAQ | More |
Repeatedly applies binary Polymorphic Function Object f to each element of a sequence and the previous state. accumulate is equivalent to fold.
template< typename Sequence, typename State, typename F > typename result_of::accumulate<Sequence, State, F>::type accumulate( Sequence& seq, State const& initial_state, F const& f);
Parameter | Requirement | Description |
---|---|---|
seq | A model of Forward Sequence, f(eN ....f(e2,f(e1,initial_state))) must be a valid expression for each element e1 to eN in seq | Operation's argument |
initial_state | Any type | Initial state |
f | A model of binary Polymorphic Function Object | Operation's argument |
accumulate(seq, initial_state, f);
Return type: Any type
Semantics: Equivalent to f(eN ....f(e2,f(e1,initial_state))) where e1 ...eN are the elements of seq.
Linear, exactly result_of::size<Sequence>::value applications of f.
#include <boost/fusion/algorithm/iteration/accumulate.hpp>
struct make_string { template<typename T, typename State> struct apply { typedef std::string type; }; template<typename T> std::string operator()(const T& t, const std::string& str) const { return str + boost::lexical_cast<std::string>(t); } }; ... const vector<int,int> vec(1,2); assert(accumulate(vec,std::string(""), make_string()) == "12");
Copyright © 2001-2005 Joel de Guzman, Dan Marsden |