views:

128

answers:

5

I just can't remember the terminology used for this and other related properties.

EDIT - Maybe such a concept doesn't exist but I remember reading something in Effective C++ (or More Effective C++) where he advocated using swaps to commit changes last in the function because the vector swap functions were guaranteed not to throw an exception.

A: 

Idempotent? It's not quite what you're describing, but it may be what you're thinking of :)

Jon Skeet
A: 

Say that it's side effect free and exception safe =)

gnud
That does actually sound familiar :)
tpower
+2  A: 

I think you mean to say that the function is "exception-safe". See e.g. http://en.wikipedia.org/wiki/Exception_safety.

The Wikipedia article further divides the safety into various levels. This is the one that is relevant here:

2. Commit or rollback semantics, also known as strong exception safety or no-change guarantee: Operations can fail, but failed operations are guaranteed to have no side effects so all data retain original values.

There's a reference to an STL design document that introduces exception safety and commit-or-rollback semantics: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1997/N1077.asc

Yes, thanks. It was these different levels of exception safety I was looking for. Maybe you could add them to your answer?
tpower
I didn't want to copy all of it, so I just quoted the one that is the most relevant here. Does that look ok?
+2  A: 

You might be thinking of an exception guarantee, in particular the "strong guarantee".

CesarB
A: 

Having read your edit, I suspect your title is slightly incorrect. Do you really mean it has no side effects whether or not an exception is thrown (as per the current wording) or that it has no side effects when an exception is thrown, but if the method completes without throwing an exception then it will/can have side effects? There's a pretty big difference :)

The latter is described in Accelerated C# 2008 as "exception neutrality".

Jon Skeet
Thanks, I fixed the wording of the question.
tpower