嗨,大家都鼓励大师!
我想在字符串向量中找到某个元素,忽略大小写:
#include <iostream>
#include <string>
#include <vector>
#include "boost/algorithm/string.hpp"
#include "boost/bind.hpp"
using std::string;
using std::vector;
bool icmp(const string& str1, const string& str2)
{
return boost::iequals(str1, str2);
}
int main(int argc, char* argv[])
{
vector<string> vec;
vec.push_back("test");
// if (std::find_if(vec.begin(), vec.end(), boost::bind(&boost::iequals<string,string>, "TEST", _1)) != vec.end()) <-- does not compile
if (std::find_if(vec.begin(), vec.end(), boost::bind(&icmp, "TEST", _1)) != vec.end())
std::cout << "found" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这个工作正常,但我想知道的是,如果有可能摆脱额外的函数(icmp())并直接调用iequals(模板函数)(如在注释行中).
提前致谢!
添加模板参数和默认语言环境参数适用于我的机器.
if (std::find_if(vec.begin(), vec.end(), boost::bind(&boost::iequals<string,string>, "TEST", _1, std::locale())) != vec.end())
std::cout << "found" << std::endl;
Run Code Online (Sandbox Code Playgroud)
编译器是VS2010.
| 归档时间: |
|
| 查看次数: |
2342 次 |
| 最近记录: |