【发布时间】:2017-06-15 04:57:05
【问题描述】:
我正在尝试使用std::regex_match() 作为std::count_if() 中的谓词和类成员函数中的std::vector<string> 元素。但不知道如何才能正确地将第二个参数(正则表达式值)绕过到函数中。
有没有办法将std::regex_match() 用作谓词(例如std::bind1st())?
例子:
int GetWeight::countWeight( std::regex reg )
{
std::cout << std::count_if( word.begin(), word.end(),
std::bind1st( std::regex_match(), reg ) );
return 1;
}
word 是 vector<std::string>,我需要计算匹配 std::regex reg 的元素绕过类外。
【问题讨论】:
-
如果签名不完全匹配,你不能直接插入它。虽然下面的答案看起来不错。