![]() |
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);
Table 1.34. Parameters
|
Parameter |
Requirement |
Description |
|---|---|---|
|
|
A model of Forward
Sequence, |
Operation's argument |
|
|
Any type |
Initial state |
|
|
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 applications of result_of::size<Sequence>::valuef.
#include <boost/fusion/algorithm/iteration/accumulate.hpp>
struct make_string { template<typename T, typename State> struct result { 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); } }; ... constvector<int,int> vec(1,2); assert(accumulate(vec,std::string(""), make_string()) == "12");
| Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger |