[regex] boost, problem compiling doc example of boost::match_extra

I am trying to use the repeat capture mechanism in regex i thought i would start with the documentation example, but im having problems compiling it. Any help is appreciated. (There is likely a problem between my seat and the keyboard) Here is my compile output: and below that is the actual example. /usr/bin/g++ -Wno-ctor-dtor-privacy -O -o file2AssocTable.o -I/afs/apd.pok.ibm.com/func/vlsi/eclipz/common/integration/OA_migration/OpenAccess/2.2.4/include/oa \ -I/afs/apd.pok.ibm.com/func/vlsi/eclipz/common/integration/OA_migration/OpenAccess/2.2.4/include -I/afs/apd.pok.ibm.com/func/vlsi/eclipz/common/integration/GNU/boost/boost_1_33_1/include/boost-1_33_1 \ -c file2AssocTable.cpp file2AssocTable.cpp: In function `void print_captures(const std::string&, const std::string&)': file2AssocTable.cpp:171: no matching function for call to ` boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::captures(unsigned int&)' file2AssocTable.cpp:177: no matching function for call to ` boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> , std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::captures(unsigned int&)' make: *** [file2AssocTable.o] Error 1
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) { std::cout << " $" << i << " = {"; for(j = 0; j < what.captures(i).size(); ++j) { if(j) std::cout << ", "; else std::cout << " "; std::cout << "\"" << what.captures(i)[j] << "\""; } std::cout << " }\n"; } } else { std::cout << "** No Match found **\n"; } }

Rick Weiss wrote:
I am trying to use the repeat capture mechanism in regex i thought i would start with the documentation example, but im having problems compiling it. Any help is appreciated.
(There is likely a problem between my seat and the keyboard)
:-) This is likely the same issue that came up yesterday (!), the extended capture information is optional (see http://www.boost.org/libs/regex/doc/captures.html) to use it both your code and Boost.Regex must be compiled with BOOST_REGEX_MATCH_EXTRA defined. The best place to define it is in boost/regex/user.hpp BTW then you can't forget it :-) HTH, John.

Thanks John, that was the problem, it works now. John Maddock wrote:
Rick Weiss wrote:
I am trying to use the repeat capture mechanism in regex i thought i would start with the documentation example, but im having problems compiling it. Any help is appreciated.
(There is likely a problem between my seat and the keyboard)
:-)
This is likely the same issue that came up yesterday (!), the extended capture information is optional (see http://www.boost.org/libs/regex/doc/captures.html) to use it both your code and Boost.Regex must be compiled with BOOST_REGEX_MATCH_EXTRA defined. The best place to define it is in boost/regex/user.hpp BTW then you can't forget it :-)
HTH, John.

Yep, i was right, problem between my seat and the keyboard. boost.regex ROCKS, this repeat stuff is awesome, a huge code/time saver Thank You. John Maddock wrote:
Rick Weiss wrote:
I am trying to use the repeat capture mechanism in regex i thought i would start with the documentation example, but im having problems compiling it. Any help is appreciated.
(There is likely a problem between my seat and the keyboard)
:-)
This is likely the same issue that came up yesterday (!), the extended capture information is optional (see http://www.boost.org/libs/regex/doc/captures.html) to use it both your code and Boost.Regex must be compiled with BOOST_REGEX_MATCH_EXTRA defined. The best place to define it is in boost/regex/user.hpp BTW then you can't forget it :-)
HTH, John.
participants (2)
-
John Maddock
-
Rick Weiss