Search code examples
c++boostboost-xpressive

Xpressive >>= Operator


I am toying around with Boost Xpressive and am having trouble with the following snippet

#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;
 }

The result of running this program is a match of 1 as opposed to the expected 12. Does the sregex::operator>>= have a different meaning/use what I intuitively assumed? I was expecting this to yield an sregex similar to _d >> _d.


Solution

  • Xpressive doesn't support the >>= operator. The fact that this code compiles at all could be considered a bug. Try:

    rex = rex >> _d;
    

    However, building up a regex piecemeal like this will make the regex perform poorly.