Prev: Is std::move going to be at least as fast as RVO?
Next: Can there be parallel initialization of global variables in C++0x?
From: Jesse Perla on 27 May 2010 17:05 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&? -Jesse -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |