Boost logo

Boost :

From: Charles Fox (charles.fox_at_[hidden])
Date: 2006-11-07 10:16:38


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk