Boost logo

Boost Users :

From: Hendrik Schober (yg-boost-users_at_[hidden])
Date: 2002-06-24 10:32:19


"the_d.geo" <coracao_at_[hidden]> wrote:
> [...]
> stringbuf line;
> ...
> string tmp = line.str();
> if (regex_match(tmp, matchInfo, linerx)) {
> string name = regex_format(matchInfo, "$1");
> }
> [...]

  John has already eyplained, why it won't work
  with a temporary. In addition to that, you can
  avoid the copying of the string, too, by taking
  advantage of the fact that temporaries bound to
  constant references will won't be destroyed for
  the reference's lifetime:

    const string& tmp = line.str(); // note the const ref
    if (regex_match(tmp, matchInfo, linerx)) {
       string name = regex_format(matchInfo, "$1");
    }

  Schobi


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net