Re: why a member "swap" function shouldn't throw?
Kai-Uwe Bux <jkherciueh@gmx.net> wrote:
Daniel T. wrote:
Kai-Uwe Bux <jkherciueh@gmx.net> wrote:
Daniel T. wrote:
My point is, if you are writing a class, and you want to
provide an exception safe swap, then you have no excuses...
Just do it.
I doubt the "therefore" part, but maybe, I am missing something.
Could you demonstrate/illustrate your claim by providing an
implementation of the pair-template (known from std::pair) with
an added thread safe swap member?
What made you snip the sentence that I was explicitly referring to?
You were referring to an ancillary comment rather than addressing the
point I was making. As the part I didn't snips says, "My point is..."
Your claim, as I understood it, was that _any class_ can provide an
exception safe swap _because_ one can always use pimpl. I still
don't see how to do that for std::pair<>.
No, my claim as I have actually stated is, "If you are writing a
class, and you want to provide an exception safe swap, then you can do
that."
Again, if you are writing a class, and you want to provide an
exception safe swap, then you have no excuses.
I agree that if you _design_ a class (as opposed to provide an
implementation for an already specified class) you can make sure
that a swap member can be implemented in an exception safe way
(provided you have similar control over all member objects).
Again, you don't need "similar control over all member objects." If
you are *designing* the class then you *can* provide an exception safe
swap. (period, full-stop.) No "provided", no excuses.
You are right to make that point. It is an important point that puts
the problem into the context of class design, where it belongs. I
just thought that your pimpl remark might be an overgeneralization.
Accepted.