为什么mem_fn在与smatch :: str一起使用时无法编译?

时间:2016-09-13 20:53:08

标签: c++

这看起来很简单,也很无辜,却因为失败的替换而失败了#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);

http://ideone.com/nsN8A1

1 个答案:

答案 0 :(得分:4)

因为str takes an argument。通常默认为0,但mem_fn不带默认参数值,因此必须明确提供。

string first_word = f(m, 0);

http://ideone.com/nfuTFX