The algorithm you are using works on the samples
collection, which is an attribute of the class Entity
. The collection is an instance of the vector template.
The std::for_each
instance works only on iterators of the collection, which are passed at construction time : samples.begin()
and samples.end()
.
Standard iterators are especially designed to abstract the notion of cursor or pointer on a collection. They do not duplicate the collection in any way, so you should not worry about memory allocation issue when using these.
The specific accumulator_set
used here also doesn't produce any copy of the collection. It merely access the iterator, does a comparison between the current min candidate and the current pointed value of the collection, and keep the best of both for the next iteration.
As it stands, none of the standard parts you are using duplicates the collection.