0

I'm having an extremely frustrating time trying to get the Boost regex library to behave itself in XCode 8.

I've finally managed to sort the includes out, now I'm hitting compiler errors when attempting to run the following regex example from Boost's library documentation here.

The code is as follows:

void print_captures(const std::string& regx, const std::string& text)

{
boost::regex e(regx);
boost::smatch what;
std::cout << "Expression:  \"" << regx << "\"\n";
std::cout << "Text:        \"" << text << "\"\n";
if(boost::regex_match(text, what, e, boost::match_extra))

{
    unsigned i, j;
    std::cout << "** Match found **\n   Sub-Expressions:\n";
    for(i = 0; i < what.size(); ++i)
        std::cout << "      $" << i << " = \"" << what[i] << "\"\n";
    std::cout << "   Captures:\n";
    for(i = 0; i < what.size(); ++i) 
    // compiler error in line above
    {
        std::cout << "      $" << i << " = {";
        for(j = 0; j < what.captures(i).size(); ++j)

    // compiler erro in line above
        {
            if(j)
                std::cout << ", ";
            else
                std::cout << " ";
            std::cout << "\"" << what.captures(i)[j] << "\"";
        }
        std::cout << " }\n";
    }
}
else
{
    std::cout << "** No Match found **\n";
}
}

int main(int , char* [])
{
    print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
    print_captures("(.*)bar|(.*)bah", "abcbar");
    print_captures("(.*)bar|(.*)bah", "abcbah");
    print_captures("^(?:(\\w+)|(?>\\W+))*$",
               "now is the time for all good men to come to the aid of the party");
return 0;
}

I'm getting two errors at the points indicated in the block above that both read:

 No member named 'captures' in 'boost::match_results<std::__1::__wrap_iter<const char *>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<const char *> > > >'

Apologies in advance if this question has been answered elsewhere.

Any idea how I can fix this?

DanielH
  • 176
  • 1
  • 16
  • My feeling is that somehow you are linking a different version of boost, the documentation says this is an experimental feature so maybe it is not included in the version of the library you are using – Marco Nov 04 '16 at 15:32
  • I think you may be right about that. The Boost documentation is really good, but the libraries do not play nicely with Xcode. Think I might just plump for the standard `regex` library. – DanielH Nov 04 '16 at 15:42
  • 1
    Check also the last 2 lines of the doc page: Unfortunately enabling this feature has an impact on performance (even if you don't use it), and a much bigger impact if you do use it, therefore to use this feature you need to: Define BOOST_REGEX_MATCH_EXTRA for all translation units including the library source (the best way to do this is to uncomment this define in boost/regex/user.hpp and then rebuild everything. Pass the match_extra flag to the particular algorithms where you actually need the captures information (regex_search, regex_match, or regex_iterator). – Marco Nov 04 '16 at 15:49
  • I think that nails it, actually. Many thanks, Marco. – DanielH Nov 04 '16 at 16:10

0 Answers0