[Cs3] using functors with algorithms

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Jun 26 19:42:59 EDT 2015


CS3 students,

first and foremost. It turns out it is not a good idea to use functors
that modify its state between invocations with algorithms. The problem
is that it is not guaranteed how the algorithms are implemented. They
may copy a functor, replicate it, etc. 

You can still use a stateful functor, it just the overloaded function
operator   

	   operator()  

that is used in algorithms, should not change this state. I came up
with an example usage here:

     http://vega.cs.kent.edu/~mikhail/classes/cs3/Examples/STL/Algorithms/Functors/functorGenerate.cpp

Thanks,
-- 
Mikhail


More information about the cs3 mailing list