私は構造体のベクトルの要素を見つけようとしています。このコードは、大文字と小文字を区別して検索するときに機能します。大文字と小文字を区別しないように強調しようとすると、2つの問題が発生します。単にboost/algorithm/string.hpp
休憩前に作業VS2010ビルドを含めブーストフェニックスを使用して、starts_withでfind_if呼び出しを呼び出すにはどうすればよいですか?
。エラーは "'boost :: phoenix :: bind':オーバーロードされた関数へのあいまいな呼び出しです。" XcodeでOKをビルドします。バインドを曖昧さを解消する方法はありますか?
私は、2番目の(コメントアウトされた)find_if行に構文が間違っていて、istarts_with呼び出しを追加していると思います。私はフェニックスのヘッダから "エラー:タイプが 'タイプ'ではないというエラーを受け取ります。問題#1を修正できると仮定して、この行を修正する方法は?
ありがとう!
コード:
#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;
}
どのバージョンのBoostを使用していますか? – MDman
ブースト1.48.0を使用する。 –