मैं structs के वेक्टर में एक तत्व खोजने की कोशिश कर रहा हूँ। कोड केस-संवेदी तरीके से खोजते समय कोड काम करता है। जब मैं केस-असंवेदनशील होने के लिए इसे बढ़ाने की कोशिश करता हूं, तो मैं दो मुद्दों में भाग लेता हूं।बूस्ट फीनिक्स का उपयोग करके, मैं start_if कॉल के साथ start_if कॉल कैसे शुरू कर सकता हूं?
बस
boost/algorithm/string.hpp
समेत पहले काम कर रहे वीएस -2010 बिल्ड को तोड़ देता है। त्रुटि "बूस्ट :: फीनिक्स :: बाइंड 'है: अधिभारित कॉल ओवरलोडेड फ़ंक्शन"। एक्सकोड में ठीक बनाता है। बंधन को अलग करने का कोई तरीका?मुझे लगता है कि मुझे दूसरी बार (टिप्पणी की गई) 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;
}
बूस्ट का कौन सा संस्करण आप उपयोग कर रहे हैं? – MDman
बूस्ट 1.48.0 का उपयोग कर। –