0

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;
std::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?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
mkaes
  • 13,781
  • 10
  • 52
  • 72

1 Answers1

0

Try:

#include <boost/phoenix/fusion.hpp>

using boost::phoenix::arg_names::arg1;

fusion::for_each(fmap, boost::phoenix::at_c<1>(arg1).DoIt() );
Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • On my VS2010 I get an error `error C2780: 'const boost::phoenix::detail::expression::function_eval::type boost::phoenix::at(const A0 &,const A1 &)' : expects 2 arguments - 1 provided` – mkaes Oct 06 '11 at 13:18
  • Which version of Fusion you're using? – Nawaz Oct 06 '11 at 13:20
  • @mkaes: Ohh.. I can't even test it. Anyway, I had asked similar question once, now my problem is working. Maybe you should look into this topic : http://stackoverflow.com/questions/7337414/how-can-i-make-stdfind-if-and-stdmap-work-together-using-some-boost-library – Nawaz Oct 06 '11 at 13:22
  • 2
    I'm pretty sure you mean `phoenix::at_c<1>` rather than `phoenix::at<1>`. – ildjarn Oct 06 '11 at 17:50