Ulrich Achleitner wrote:
On Wed, 26 Jan 2005 11:28:25 +0100, Jef Driesen
<je********@hotmail.com.nospam> wrote:
Is there an STL algorithm that does something like
for (iterator i = begin(); i != end(); ++i)
f(*i,value);
where f results in the expression *i += value. I already found the
algorithm 'transform' with the 'plus' function object, but it does
evaluate to *i = *i + value. And this is not exactly what I want.
maybe
template<class InputIterator, class Distance> void
advance(InputIterator& _InIt, Distance _Off);
from <iterator> is what you need?
I don't need to advance the iterator itself, but add (or substract,
multiply, divide,...) a value to the object where the iterator points
to. I want this to implement these operators for my own container (2D
vector):
vector<T>& operator+=(const vector<T>& rhs)
vector<T>& operator+=(const T& rhs)
without having to rewrite the same loop in every function. The problem
is not the algorithm (I can write my own) but the function object for
operator+= on the elements. In the copy constructor and assignment
operator I can use std::copy and std::fill. I want something similar for
operator +=