Access member of returned struct in boost lambda/phoenix

138 views Asked by At

I want to replace some older code with simpler, functor based code. But I don't want to introduce a functor class for this and use boost::lambda/phoenix for this as I don't have C++11 at hand.

Old code looks like this

int player = ...;
Point middlePt = ...;
for(Point pt=<magic with nested loops>)
  if(this->IsMilitaryBuilding(pt) && (this->GetNode(pt).owner == player + 1))
    return true;
return false;

I have a function that calls Functor for every point (encapsulating the magic) and returns true when any of those calls returns true:

template<class Functor>
bool CheckPts(Point middlePt, Functor f);

Translating this for the first part of the if is easy:

return CheckPts(middlePt, bind(&IsMilitaryBuilding, this, _1));

And for the 2nd I'd want to do something like: bind(&GetNode, this, _1).owner == player+1 which is not supported.

What is the most readable way of doing this? I think this might be solvable by binding a reference to this and calling the functions directly using phoenix lambda but I did not found any references that go beyond simple 'Hello World' lambdas accessing only a simple member or a parameter.

0

There are 0 answers