使用 boost::phoenix 的简单示例:
#include <vector>
#include <algorithm>
#include <boost/phoenix.hpp>
namespace ph = boost::phoenix;
namespace place = boost::phoenix::placeholders;
struct A
{
int val_;
explicit A(int i) : val_(i) {}
int foo() { return val_;}
};
int main()
{
std::vector<A> coll;
coll.push_back(A(2));
coll.push_back(A(4));
coll.push_back(A(5));
coll.push_back(A(7));
std::vector<A>::const_iterator cit;
cit = std::find_if(coll.begin(), coll.end(), ph::bind(&A::foo, place::_1) % 2 == 1);
int val = (*cit).val_;
return 0;
}
它可以编译,但在 VS2008 的输出中有一些警告:
c:\boost_1_47_0\boost\phoenix\bind\detail\member_variable.hpp(54) : 警告 C4180:应用于函数类型的限定符没有意义;忽略
它来自哪里:1)代码不正确2)再次出现MS问题。3) boost::phoenix 库做得不好?