Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2002-10-31 02:11:48


----- Original Message -----
From: "Martin" <m_at_[hidden]>

> I am creating the "Special Object" within the function. Actually I am
> working on a template for programming by contract.
>
> Q: how many of you people are using programming by contract already in
C++?
some, but too few.

> Q: do you think there is no practical solution in C++?
no, there is. I might not be a full design by contract scheme, but it's good
enough.
My approach relyes on macros just like the one find in the boost yahoo
dierctories, and one can choose
to to throw exceptions or call normal 'assert' like functions which exits
immediately.

There is very little automation, except that one can make for class
hierarchies:

class Base_base
{
public:
    virtual void foo() = 0;
};

class Base
{
Base_base* obj_;
public:
   void foo()
  {
    //preconditions
     obj_->foo();
    //postconditions
  }
};

I code the class invariant as a function which is at least called from
the constructor body; Actually it should be called from any
public non-const function.

I can set up a link with my macros so you can see it, but it pretty similar
to that at yahoo except
for its style: I don't use capital letters for the macros but think of the
words as reserved and I always pass a comment
along with the asssertion, eg.

require( "valid pointer", ptr );

regards

Thorsten Ottosen, AAU


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