c++boostlazy-evaluationboost-phoenix

Troubles with boost::phoenix::function


Using boost::phoenix::function I encountered some problems. As far as I know this lazy function requiries functor as its template parameter. I have to define a functor class/structure and then pass it as a template parameter for instantiation. But it's too long and redundant. Can I use some other callable type for phoenix::function creation (function reference/pointer etc.)? I tried lambdas:

 const auto foo = [] { cout <<"Test"; }
 const boost::phoenix::function<decltype(foo)> lazy;

but call to lazy() didn't compile. So the question are there any alternatives instead of functor classes for fast one-line phoenix::function creation?


Solution

  • Since the type of foo isn't default constructible, lazy needs an initializer:

    boost::phoenix::function<decltype(foo)> lazy { foo };