这看起来很简单,也很无辜,却因为失败的替换而失败了#34;致电f(m)
。那是为什么?
string const input = "The quick brown fox.";
std::regex const words("[^\\s]+");
auto f = std::mem_fn(&std::smatch::str);
std::sregex_iterator i = std::sregex_iterator(input.begin(), input.end(), words);
std::smatch m = *i;
string first_word = f(m);
答案 0 :(得分:4)
因为str
takes an argument。通常默认为0
,但mem_fn
不带默认参数值,因此必须明确提供。
string first_word = f(m, 0);