In the quest for improving the quality of the MMS code in 1.1.0 I’ve done several things, one of which was to convert all the source to the boost foreach statement. Since I liked the result of the foreach cleanup so much, I decided to see what other libraries could be of use. I quickly found the function and bind library which allowed me to remove the internal function pointers framework we have currently been using. While converted I was surprised to see how cleaner the code became. The bind function is truly easy to use and read and made it possible to remove several helper classes which only purpose was to capture state to create a uniform interface.
So instead of:
class FP { std::listnumbers; FP(std::list n) : numbers(n) {} call(int t) { int total; foreach (int i, numbers) total += i*t; return total; } };
(I saved the part of actually creating the function pointer object). One gets:
call(int t, std::listnumbers) { int total; foreach (int i, numbers) total += i*t; return total; } boost::bind(&call, _1, list_of_numbers);
Voila. Now if only the wordpress code formatting didn’t suck so much 😉