
On Thu, Nov 24, 2011 at 12:56 PM, Thomas Klimpel <Thomas.Klimpel@synopsys.com> wrote:
Dean Michael Berris wrote:
Or better yet, works now:
namespace foo { void non_local_function(int i, bool b, long l, std::string const & s) { // do what I want here. }
void f(std::vector<double> const &v) { int i; bool b; long l; for_each(begin(v), end(v), bind(&non_local_function, i, b, l, _1)); } }
See, no voodoo required here.
To be honest, this one really looks nice and convincing. I find it even looks nicer than the C++11 Lambda. And as you wrote in response to Lorenzo:
But I did show a solution that works in both C++03 and C++11 which is to use bind to do it and a non-local function. Phoenix already enables
As you say this solution, which works on both C++03 and C++11, does not implement a local function. N2511 indicates one prospective arguing maintenance and readability benefits when the function can be declared locally, e.g., just above the for_each in this case. That is not possible in your example. That's what Boost.Local does instead. (Note that with your example above you also explicitly specified the bound types but I'm sure you can workaround that with templates so I'm not arguing this point as an issue.) Now, it is really OK if you think that local functions are not needed. IMO, as a user you should be fully empowered to use or not a library based on your personal preferences and the needs of your problem domain. As for the library under review, as I said, the reviewers have directly spoken to the question of whether local functions are or not useful:
- What is your evaluation of the potential usefulness of the library?
HTH, --Lorenzo