Boost phoenix actor as a fusion callable object
I was wondering if it was possible to create callable phoenix actors and use them in fusion sequences. Given the following source:
struct FusionStruct
{
void Doit() const{std::cout << "Doit" << std::endl;}
};
struct FusionCaller
{
template <typename T> void operator()(T& x) const
{
x.second.Doit();
}
};
int main()
{
typedef boost::fusion::map<boost::fusion::pair<int, FusionStruct> > FusionMap_t;
FusionMap_t fmap(boost::fusion::make_pair<int>(FusionStruct()));
boost::fusion::for_each(fmap, FusionCaller());
return 0;
}
This works as expected.
But since I can create polymorphic callable actors in phoenix like this:auto p = (boost::phoenix::placeholders::arg1 * boost::phoenix::placeholders::arg1);
// int and double are fine
std::cout << p(2,2) << std::endl;
st开发者_JS百科d::cout << p(2.0,2.0) << std::endl;
I was wondering if I can use phoenix to get rid of my FusionCaller struct. Like this:
fusion::for_each(fmap, /* some magic phoenix expression*/);
So is this possible at all with phoenix?
Try:
#include <boost/phoenix/fusion.hpp>
using boost::phoenix::arg_names::arg1;
fusion::for_each(fmap, boost::phoenix::at_c<1>(arg1).DoIt() );
精彩评论