Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-08 01:44:57


Hurd, Matthew wrote:
> Another need is to support the hierarchical chaining of conditions to
> support stronger and weaker conditions to model appropriate polymorphic
> substitutability.

That doesn't apply to invariants, but to preconditions and
postconditions: preconditions can only be relaxed by inheritance, while
postconditions can only be tightened. AFAICS this is next to impossible
to achieve in C++ without language support:

class base
{
    virtual void f();
};

class derived : public base
{
    void f();
};

We need and object inside function f() that triggers a check of
preconditions in its constructor, and a check of postconditions in its
destructor. And its type is uniquely designed for that function, so,
presumably, we'd define it inside the function...

void base::void()
{
    class conditions
    {
       conditions()
       {
          ...basef_preconditions...
       }
       ~conditions()
       {
          ...basef_postconditions...
       }
    }
    checker_obj;
    ...
}

Now, in the derived class, we ned to OR any preconditions in the
overriding function, and AND any new postconditions in the overriding
function, with the preconditions and postconditions in the conditions
class in base::f():

void derived::void()
{
    class conditions
    {
       conditions()
       {
          ...basef_preconditions... || ...derivedf_preconds...
       }
       ~conditions()
       {
          ...basef_postconditions... && ...derivedf_postconds..
       }
    }
    checker_obj;
    ...
}

  The question is, though, how do we extract the preconditions and
postconditions from a class declared inside a function of the base class?

Cheers!


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