Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-30 12:49:52

On Wed, Oct 29, 2003 at 11:53:28PM -0800, E. Gladyshev wrote:
> For example if you know that that a type X gives
> basic guarantees, how would you *typically* use this
> knowledge when designing the rest of the program!?

In the case of the basic exception safety guarantee, I believe it works
like this:

   Do I have the basic guarantee?

    - case "no": either ensure that no exceptions will ever be thrown,
                 ever, or else give up and go home

    - case "yes": continue on with your day

(That is, you typically jusy "gotta have it".)

In the case of the strong guarantee, you also know about the state an
object is left in after an exception during an operation ("rollback").

> So the question is are basic/strong guarantees of any help
> in this hard job... and if so then how?

I think yes, but only to the minor extent suggested above.

Looking at the bigger picture, I think the point is that, while theory
about class invariants can be useful both to help you choose a
representation type, and to think about pre/post-conditions on methods
in the public interface, this theory will not help you in the middle of
a method body. During the execution of a method, you can break
invariants as you see fit, provided things are all patched up again by
the time execution gets back out to client code. As a result, in the
middle of a method, you just have to "do the correct thing"; there
aren't necessarily any explicit invariants around to help you out.

-Brian McNamara (lorgon_at_[hidden])

Boost list run by bdawes at, gregod at, cpdaniel at, john at