c – 如何绑定模板函数
发布时间:2020-12-16 03:25:53 所属栏目:百科 来源:网络整理
导读:嗨,大家都鼓励大师! 我想在字符串向量中找到某个元素,忽略大小写: #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,co
嗨,大家都鼓励大师!
我想在字符串向量中找到某个元素,忽略大小写: #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(),boost::bind(&icmp,_1)) != vec.end()) std::cout << "found" << std::endl; return 0; } 到目前为止这个工作正常,但我想知道的是,如果有可能摆脱额外的函数(icmp())并直接调用iequals(模板函数)(如在注释行中). 提前致谢! 解决方法
添加模板参数和默认语言环境参数适用于我的机器.
if (std::find_if(vec.begin(),_1,std::locale())) != vec.end()) std::cout << "found" << std::endl; 编译器是VS2010. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |