
Hi there, I'm new to boost, and am trying to install and test it on a Fedora FC3 machine with gcc 3.4.3. I have installed boost into the default locations /usr/local/lib and /usr/local/include/boost-1_33_1 respectively with bjam as instructed. I then try to compile the example regex program (copied below) with this command: g++ -L/usr/local/lib -I/usr/local/include/boost-1_33_1 -lboost_regex-gcc-1_33_1 test.cpp but I get this error: test.cpp: In function `void print_captures(const std::string&, const std::string&)': test.cpp:23: error: 'class boost::smatch' has no member named 'captures' test.cpp:29: error: 'class boost::smatch' has no member named 'captures' Note that when I comment out the lines marked in the code below, it compikes. So only the captures bits are going wrong. I noticed there was an old boost installation on this FC3 in /usr/include/boost and /usr/lib respectively. I've renemaed the former; the second I've left in case other programs are relying on it. I'm guessing that the API has changed and this captures thing is new -- any ideas about how best to make this work? (btw, what exactly are the conventions for installing into /usr/include and /usr/lib rather than their local counterparts? Where should boost correctly live?) Thanks, Charles --------- #include <boost/regex.hpp> #include <iostream> 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) { //---------------comment out from here 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"; } //------------ to here } 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; }

Charles Fox wrote:
Hi there, I'm new to boost, and am trying to install and test it on a Fedora FC3 machine with gcc 3.4.3. I have installed boost into the default locations /usr/local/lib and /usr/local/include/boost-1_33_1 respectively with bjam as instructed. I then try to compile the example regex program (copied below) with this command:
g++ -L/usr/local/lib -I/usr/local/include/boost-1_33_1 -lboost_regex-gcc-1_33_1 test.cpp
but I get this error: test.cpp: In function `void print_captures(const std::string&, const std::string&)': test.cpp:23: error: 'class boost::smatch' has no member named 'captures' test.cpp:29: error: 'class boost::smatch' has no member named 'captures'
Two points: the -l option always has to appear *after* the source files that need the library in question, and the extended-captures information is only available when both the library, *and* your code is built with BOOST_REGEX_MATCH_EXTRA defined. See http://www.boost.org/libs/regex/doc/captures.html for documentation explaining this. Also note that building with BOOST_REGEX_MATCH_EXTRA defined is likely to have an impact on regex performance - you only need it if you really want to capture all occurances of a repeated sub-expression: normal perl-style sub-expression's work just fine without it. HTH, John.

On Tue, 7 Nov 2006, John Maddock wrote:
Charles Fox wrote:
Hi there, I'm new to boost, and am trying to install and test it on a Fedora FC3 machine with gcc 3.4.3. I have installed boost into the default locations /usr/local/lib and /usr/local/include/boost-1_33_1 respectively with bjam as instructed. I then try to compile the example regex program (copied below) with this command:
g++ -L/usr/local/lib -I/usr/local/include/boost-1_33_1 -lboost_regex-gcc-1_33_1 test.cpp
but I get this error: test.cpp: In function `void print_captures(const std::string&, const std::string&)': test.cpp:23: error: 'class boost::smatch' has no member named 'captures' test.cpp:29: error: 'class boost::smatch' has no member named 'captures'
Two points: the -l option always has to appear *after* the source files that need the library in question, and the extended-captures information is only available when both the library, *and* your code is built with BOOST_REGEX_MATCH_EXTRA defined. See http://www.boost.org/libs/regex/doc/captures.html for documentation explaining this. Also note that building with BOOST_REGEX_MATCH_EXTRA defined is likely to have an impact on regex performance - you only need it if you really want to capture all occurances of a repeated sub-expression: normal perl-style sub-expression's work just fine without it.
HTH, John.
Thanks -- I did not realize captures were an optional extra -- yes I am happy with the other perl-style matching. charles
participants (3)
-
Charles Fox
-
Charles Fox
-
John Maddock