Boost logo

Boost :

From: Dirk Gerrits (dirk_at_[hidden])
Date: 2002-10-27 13:59:40


Martin wrote:

> Looking at your code gave me the idea that the precondition and the
> postcondition could be both implemented in the constructor and a
> destructor of some class of which there is an instance in the
> function. Then there is really no need for virtual precondition() and
> postcondition().

Sounds like a great idea! Perhaps a technique like this one could be
used: http://www.cuj.com/experts/1812/alexandr.htm?topic=experts

PrePostCondition guard = MakePrePostCondition(&precondition,
&postcondition);

> Only i am not sure about unwinding the stack when exceptions are thrown.

Additionally, would you want to check your postconditions when
exceptions are thrown? I think there are situations both in favor and
against that.

> >Further, is there any reason why you put the assert in pre- and
> >postcondition? Couldn't contract just as well do assert(precondition)
> >and assert(postcondition)?
>
>
> i suppose you could. i would expect that typically pre and post conditions
> would be throwing exceptions.

Ah I see. I was thinking more along the lines of this:

if (!precondition) throw PreConditionError;
...
if (!postcondition) throw PostConditionError;

In otherwords: making the pre- and postconditions nullary predicates
(that's probably a contradiction but I think you know what I mean ;) and
having the 'guard' do the asserting/throwing.

Regards,
Dirk Gerrits


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk