Using boost phoenix, how can I call find_if with start_with?

I am trying to find an element in a structs vector. The code is case sensitive. When I try to improve it so that it is not case sensitive, I run into two problems.

  • Just turning it on boost/algorithm/string.hppinterrupts the previously running build of VS2010. Error: “boost :: phoenix :: bind”: ambiguous call of the overloaded function. ”Builds OK in Xcode. Any way to fix the binding?

  • I assume that in the second (commented out) line of find_if, I have the syntax by adding a call to istarts_with. I get errors from phoenix headers saying "error: no type named 'type". Assuming problem # 1 can be fixed, how do I fix this line?

Thank!

The code:

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp> // This include breaks VS2010!
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/stl/algorithm.hpp>
using namespace boost::phoenix;
using boost::phoenix::arg_names::arg1;
using boost::istarts_with;
using std::string;
using std::cout;

// Some simple struct I'll build a vector out of
struct Person
{
    string FirstName;
    string LastName;
    Person(string const& f, string const& l) : FirstName(f), LastName(l) {}
};

int main()
{
    // Vector to search
    std::vector<Person> people;
    std::vector<Person>::iterator dude;

    // Test data
    people.push_back(Person("Fred", "Smith"));

    // Works!
    dude = std::find_if(people.begin(), people.end(), bind(&Person::FirstName, arg1) == "Fred");
    // Won't build - how can I do this case-insensitively?
    //dude = std::find_if(people.begin(), people.end(), istarts_with(bind(&Person::FirstName, arg1), "Fred"));

    if (dude != people.end())
        cout << dude->LastName;
    else
        cout << "Not found";
    return 0;
}
+5
1

, . :

int istw(string a, string b) { return istarts_with(a,b); }

find_if:

bind(&istw,bind(&Person::FirstName, arg1),"fred")

:

  • , bind, : boost::phoenix::bind.
  • istw, , , .
+2

All Articles