On 20/02/07, Joseph Artsimovich <joseph@stripped> wrote:
> > Why not use the best of both worlds, take a const-reference to the
> > string returned by stringbuf::str and then you don't need to care how
> > your strings are implemented:
> >
> > Query::preview_char()
> > {
> > std::string const& str(sbuffer_.str());
> > char* s = new char[str.size() + 1];
> > memcpy(s, str.c_str(), str.size() + 1);
> > }
> That's not going to work, as stringbuf::str() returns by value.
So what?
The temporary is guaranteed to exist as long as the reference is in scope.
See 12.2 paragraph 5 in the C++ standard.
jon