
On Thu, Dec 1, 2011 at 3:46 AM, Lorenzo Caminiti <lorcaminiti@gmail.com>wrote:
On Thu, Nov 24, 2011 at 1:14 PM, Thomas Heller <
On Sat, Nov 26, 2011 at 7:28 AM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote: thom.heller@googlemail.com> wrote:
Here is what I have to propose: Why not combine Boost.Local and Boost.Phoenix and keep everybody happy?
Hello Thomas, Joel, Hartmut, et alt. Sorry for asking again... I know we are all trying to get disintoxicated from the last week's discussions :)
int main() { using boost::phoenix::arg_names::arg1;
std::vector<int> v(3); v[0] = 1; v[1] = 2; v[2] = 3; int offset = 10;
// Phoenix function defined locally: int BOOST_LOCAL_FUNCTION_PARAMS(int x, bind offset) { int total = x + offset; std::cout << total << std::endl; return total; } BOOST_LOCAL_FUNCTION_NAME(local_add)
boost::phoenix::function<BOOST_LOCAL_TYPEOF(local_add)> pl_add = local_add; std::for_each(v.begin(), v.end(), pl_add(arg1));
return 0; }
Would this ability to plug local functions into Phoenix be useful?
// some global scope template<typename Arg1> Arg1 BOOST_PHOENIX_FUNCTION_TPL(Arg1 const& n) { return (n <= 0) ? 1 : n * (*this)(n - 1); } BOOST_PHOENIX_FUNCTION_END(factorial_impl);
boost::phoenix::function<factorial_impl> f;
Is there any interest in the above macros to define Phoenix functions at global scope?
I don't think this would be all that useful. If you're doing doing something simple enough with Phoenix that it could just be rolled into the local function, you should probably just do that (e.g., the "pl_add(arg1)" above might as well just be "local_add"). If it's more complicated than that, maybe you should just "suck it up" and define it out-of-line. I wouldn't think you would get much extra mileage from mixing local functions with Phoenix. - Jeff