Prev: Can there be parallel initialization of global variables in C++0x?
Next: Can there be parallel initialization of global variables in C++0x?
From: Goran on 28 May 2010 02:11 On May 28, 10: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&? One would guess that exactly if you pass a (const) reference, you'd have a change to be inlined better. I don't know the rationale behind pass-by-value (except that then, an anon temp variable works even if parameter ) -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |