
On 11/27/07, Alexander Nasonov <alnsn@yandex.ru> wrote:
After few months of inactivity I came back to a local function syntax. Instead of trying to bind local variables, I implemented a couple of macros that simply assign a value to a function pointer:
int BOOST_LOCAL_FUNCTION(char c) { std::cout << c << '\n'; return 1; } BOOST_LOCAL_FUNCTION_DECL(a)
What is the advantage of this with respect to: struct unnamed { static void _ (char c) { std::cout << c << '\n'; return 1; }}; (&unnamed::_)('a'); It is ugly, but I find the BOOST_LOCAL_FUNCTION_DECL macros even uglier. The macros would make sense only if they made it easy to close around the environment. Lately I've been using local structures like the 'unnamed' above to create 'lambdas' for standard algorithms instead (or in addition to) Boost.Lambda. They work very well in practice: std::vector<std::vector<int> > v = ...; struct pred { static bool _ (std::vector<int> const& x, int max_sum) { return std::accumulate(x.begin(), x.end()) < y; }}; v.erase(std::remove_if(v.begin(), v.end(), boost::bind(&pred::_, _1, 10)), v.end()); Easier to use than lambda and, most importantly expecially with older compilers, compile faster! -- gpd