From: Rob Stewart (stewart_at_[hidden])
Date: 2004-06-21 11:15:23
From: "Reece Dunn" <msclrhd_at_[hidden]>
> John Nagle wrote:
> >Reece Dunn wrote:
> >>John Nagle wrote:
> >>The problems arise in the interation with basic_string_impl and how to
> >>implement swap and functions that require constructing a string object.
> >Why do you need to construct a string object to swap?
> >Just swap one character at a time.
>  How do I implement the swap function? The solution I arrived at is the
> one you suggest: to swap the data character-by-character. What you have to
Unfortunately, that makes swap() O(N), but it does allow it to be
> consider when doing this is that the strings don't exceed capacity,
> resulting in additional logic.
That should fail, shouldn't it? Yes, that would mean a swap()
that throws, but the strings aren't really swapped if you only
swap some characters.
I'm not sure which is worse: a swap() that throws or only
partially swapping. The former violates exception safety
guarantee assumptions made by other code, but the latter means
that swap() may not really swap, which violates semantics.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk