Eric Niebler wrote:
Frankly, I think the proposed design (function object passed by value, or by reference with explicitly specified template arg) is ugly. It'll be ugly both from the user's perspective and in the implementation.
OK, but why? For the fusion/functional module the implementation part turned to be rather smooth. I must admit that for algorithms (where the function isn't the first parameter) the different ordering of the template parameters slightly bugs me.
If by-value is a perf-win in the common case (perf numbers?),
I don't think it is. There are cases where it gets optimized better, however. You can observe the effect by s/F const &/F/g in libs/fusion/example/performance/functional.cpp using GCC, bjam release-mode options. Note there is only a small (but clearly measurable) difference in this case (it's not the one I've been talking about in my previous post -- too much work to reconstruct now, sorry). But, as said, numbers don't say much, since they entirely depend on the code that is to be optimized.
then I'd prefer by-ref semantics to look like this:
for_each( seq, ref(func) );
If ef wrap/unwrap optimizes out entirely, this variant looks like a nice alternative. Another one would be to forget about the whole thing. There is a 'mutable' keyword, after all -- and, alternatively, a Function Object may reference an external state. Regards, Tobias