- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
考虑带有签名者 std::regex_match(
, what对第一个参数的生命周期的限制是什么?我没有找到任何,但是当我执行以下程序时(用 VC++ 2010 编译,迭代器调试事件):
std::string const&, std::smatch& match, std::regex const& re )
int
main()
{
std::string a("aaa");
std::string c("ccc");
std::regex re("aaa(.*)ccc");
std::smatch m;
if (std::regex_match(a + "xyz" + c, m, re)) {
std::cout << m[0] << std::endl;
std::cout << m[1] << std::endl;
}
return 0;
}
它崩溃了,无疑是因为 m
中的 sub_match
只保留迭代器进入字符串,而不是拷贝。我在里面找不到任何东西禁止我的代码的标准。
FWIW:它在 boost::regex
中也不起作用,这就是std::regex
是基于。 (当然,Boost 没有记录任何关于生命周期的限制。)
最后,我想我的问题是:我应该向标准组织,还是向 Microsoft 报告错误?
最佳答案
我不记得在采用 tr1::regex
或 std::regex
期间讨论过这种可能性,所以我认为根本没有考虑过。事后看来,这当然是一个我们应该预见到的陷阱。在我的脑海中,采用 std::string&&
的重载将表示涉及一个临时文件,并且需要一个拷贝。所以我会向标准委员会报告。 (完全披露:我编写了 Dinkumware 实现,这是 Microsoft 发布的)
关于c++ - 对 std::regex_match(和 std::regex_search)参数生命周期的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11991964/
我正在开发一个使用多个 turtle 的滚动游戏。玩家 turtle 根据按键命令在 Y 轴上移动。当危害和好处在 X 轴上移动时,然后循环并改变 Y 轴位置。我尝试定义一个名为 colliding(
我不明白为什么他们不接受这个作为解决方案,他们说这是一个错误的答案:- #include int main(void) { int val=0; printf("Input:- \n
我正在使用基于表单的身份验证。 我有一个注销链接,如下所示: 以及对应的注销方法: public String logout() { FacesContext.getCurren
在 IIS7 应用程序池中有一个设置 Idle-time out 默认是 20 分钟,其中说: Amount of time(in minutes) a worker process will rem
我是一名优秀的程序员,十分优秀!