From: Mark Zaytsev on
On May 28, 4:05 am, Jesse Perla <jessepe...(a)gmail.com> wrote:
> I have some functors that have more data that I might wish and
> algorithms that execute them (e.g. some weird multidimensional
> interpolators, etc.). I wrote some algorithms that accept these by
> constant reference, with the assumption that the function supplies a
> const operator(). i.e. stuff like:
> template<typename F> double f(const F& f)
> {
> return f(.1);
>
> };
>
> I realize that the std algorithms always pass functors by value. What
> is the reasoning for this with stateless algorithms like find
> predicates, transform, etc. (I can see why std::generate might want a
> copy by value)? Is it just to allow the functors to have a non-const
> operator()? Are there any other reasons, such as lack of inlining
> with modern compilers, that I can't pass const&?
>

When you pass function you
a. pass pointer to standalone function -- no need to create excessive
ref
b. pass functor, which is usually stateless -- no need to create ref
to 0-sized object
bottom line -- it more efficient to pass function by value


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]