我正在玩Boost Xpressive,并且在以下代码段上遇到了麻烦

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>

using namespace std;
using namespace boost::xpressive;

int main()
{
    string s("123");
    sregex rex = _d;
    rex >>= _d;

    smatch what;

    regex_search(s, what, rex);

    cout << "Match: " << what[0] << endl;

    return 0;
 }

运行该程序的结果是1与预期的12相匹配。 sregex::operator>>=是否具有其他含义/使用了我直觉上假定的含义?我期望这会产生类似于sregex_d >> _d

最佳答案

Xpressive不支持>> =运算符。该代码完全可以编译的事实可以认为是一个错误。尝试:

rex = rex >> _d;

但是,像这样建立一个正则表达式将使正则表达式的性能变差。

09-28 04:16