Re: Aliasing and Exception Safety Guarantee Classification
On Dec 18, 7:02 pm, Brendon <brendon.j.co...@gmail.com> wrote:
am i just looking at
it too much and it would really just be classified as whacky?
Thanks,
Brendon.
The trouble here is that "Exception Safety" does not always mean "I
will never invoke throw." throw is just a mechanism that C++ uses to
generalize the C setjmp/longjmp mechanism. In reality it is just one
more tool to do some flow control with.
For example --
int i=0;
for(int i=0;i!=10;){
try{
B(i);//increment
}catch(int j){
std::cout<<"performed "<<j<<" iterations\n";
}}
is a perfectly good for loop, aside from the fact that it is horribly
inefficient compared to the standard way of writing loops, not to
mention will never pass even a noob's code review.
Here throw and catch are just different expressions of the function
return mechanism.
It is also possible to do other tricks, like "typed switch
statements" (which is one way of looking at a series of catch blocks)
and functions that can return more than one type, as if you could say
(int || float) foo();
It is only when throws are used to protect program invariants that
"Exception Safety Classifications" comes into play. This is the sense
that they are used in the standard containers and most of the standard
library (but not all -- IOstreams does quite a bit of exception
handling that is used more in the sense of "warnings" than invaraint
failures --in the vast majority of cases these are just absorbed by
IOstreams internally )
So in reality "throw / catch are used to protect class/function
invariants" is an idiom of C++, but not the only way of using the
exception mechanism. Just like "inheritance means Is-A" is an idiom,
but not the only interpretation of class inheritance, as any template
metaprogram will prove.
Lance
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]