2

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.

SoapBox
  • 20,457
  • 3
  • 51
  • 87
Freddie Witherden
  • 2,369
  • 1
  • 26
  • 41

1 Answers1

1

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.

Eric Niebler
  • 5,927
  • 2
  • 29
  • 43