| Home | Libraries | People | FAQ | More

##### reverse_iter_fold

###### Description

For a sequence `seq`, initial state `initial_state`, and binary function object or function pointer `f`, `reverse_iter_fold` returns the result of the repeated application of binary `f` to the result of the previous `f` invocation (`inital_state` if it is the first call) and iterators on each element of `seq`.

###### Synopsis

    template<
        typename Sequence,
        typename State,
        typename F
        >
    typename result_of::reverse_iter_fold<Sequence, State const, F>::type reverse_iter_fold(
        Sequence& seq, State const& initial_state, F f);

    template<
        typename Sequence,
        typename State,
        typename F
        >
    typename result_of::reverse_iter_fold<Sequence const, State const, F>::type reverse_iter_fold(
        Sequence const& seq, State const& initial_state, F f);

Table 1.40. Parameters

Parameter | Requirement | Description
--- | --- | ---
`seq` | A model of Bidirectional Sequence | Operation's argument
`initial_state` | Any type | Initial state
`f` | `f(s,it)` with return type ``boost::result_of`<F(S,It)>::type` must be a valid expression for current state `s` of type `S`, and for each iterator `it` of type `It` on an element of `seq` | Operation's argument

###### Expression Semantics

    reverse_iter_fold(seq, initial_state, f);

Return type: Any type

Semantics: Equivalent to `f(... f(f(initial_state,itN),itN-1) ...it1)` where `it1 ...itN` are consecutive iterators on the elements of `seq`.

###### Complexity

Linear, exactly ``result_of::size`<Sequence>::value` applications of `f`.

###### Header

    #include <boost/fusion/algorithm/iteration/reverse_iter_fold.hpp>
    #include <boost/fusion/include/reverse_iter_fold.hpp>

###### Example

    struct make_string
    {
        typedef std::string result_type;

        template<typename T>
        std::string operator()(const std::string& str, const T& t) const
        {
            return str + boost::lexical_cast<std::string>(deref(t));
        }
    };
    ...
    const vector<int,int> vec(1,2);
    assert(reverse_iter_fold(vec,std::string(""), make_string()) == "21");