views:

35

answers:

0

I would like to use Boost Phoenix to generate a lambda function for use in a std::find_if operation on a structure that contains reference-type members. A contrived example is as follows:

 struct MyStruct 
 { 
  MyStruct() : x(0) {} 
  int& x;
  };

 std::vector<MyStruct> AllStructs;

 // Search the array for an element for which x == 5
 const std::vector<MyStruct>::const_iterator& it = 
  find_if(
   AllStructs.begin(), 
   AllStructs.end(), 
   bind(&MyStruct::x, arg1) == 5
  );

If MyStruct::x is of type int instead of int&, it compiles fine. But with the reference member I get a "pointer to reference member is illegal" error.

From poking around on the net, it seems like I need to use Phoenix's 'ref' functionality, but I can't seem to figure out the required syntax.

Does anyone know how to get this to work for type 'int&' ?