Re: assert_handler?
Bob Bell wrote:
Thorsten Ottosen wrote:
John Nagle wrote:
A "public" section means you're putting the object into
a valid state, then leaving the object.
We are trying to minimize the number of new constructs. What you can do
in our proposal is to call a public member:
class someclass
{
public:
void f();
void f_helper();
};
void someclass::f()
{
... // some code
f_helper(); // would correspond to your "public section"
... // more code
}
I thing we ripped out of the proposal was to be able to call the
invariant explicitly.
Is the above not good enough?
The problem occurs when an A object, while in an "invariants suspended"
state, calls out to some function F() which then calls back to the A
object.
Either F() is calling back to A through a public function (in which
case invariants are checked),
Right.
or else F() is a friend. It seems to me
that friendship is a relationship that says "it's OK to call into A
while invariants are suspended" -- after all, a friend of A has
complete access to the implementation state of A, and can do anything
it wishes, including breaking the invariants. Therefore, if friend F()
calls back into A through some private interface that doesn't check
invariants, that's OK; in fact, I think it's the correct behavior.
Agreed.
So to answer your question, yes, what you've got is good enough,
because the only way a non-friend can get back into A is through an
operation that will check invariants.
The only quibble I have is with protected members. Suppose F() is a
member of a derived class of A. If it calls back into A through a
protected member of A, this is not the same as friendship -- protected
does not grant access to implementation.
not unless that is also protected.
Therefore, it's not OK to call
into A while invariants are suspended. So invariants must be checked on
protected member functions as well as public member functions.
I tend to agree.
-Thorsten
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]