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;
struct Person
{
string FirstName;
string LastName;
Person(string const& f, string const& l) : FirstName(f), LastName(l) {}
};
int main()
{
std::vector<Person> people;
std::vector<Person>::iterator dude;
people.push_back(Person("Fred", "Smith"));
dude = std::find_if(people.begin(), people.end(), bind(&Person::FirstName, arg1) == "Fred");
if (dude != people.end())
cout << dude->LastName;
else
cout << "Not found";
return 0;
}