开发者

Boost phoenix actor as a fusion callable object

开发者 https://www.devze.com 2023-04-11 08:54 出处:网络
I was wondering if it was possible to create callable phoenix actors and use them in fusion sequences.

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() );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号