Function Object for Method with a Single Parameter.
Supporting Design by Contract in C++
by David Maley and Ivor Spence
Listing 2. Function Object for Method with a Single Parameter.
template <typename Object, typename ReturnType, typename Formal1>
class DBC1 {
typedef ReturnType (Object::* BodyType)(const Formal1&);
bool pre(const Formal1&) const { return true; }
void preFailure() const { throw Assertion("preFailure", __FILE__, __LINE__); }
bool post(const ReturnType&, const Formal1&) const { return true; }
void postFailure() const { throw Assertion("preFailure",__FILE__,__LINE__); }
BodyType _body;
const Object *_object, *_old;
Object *_mutableObject;
public:
DBC1(Object* object, BodyType body) : _body(body),_mutableObject(object),_object(object),_old(object) { }
ReturnType operator()(const Formal1&);
};
About the Authors
David Maley is with St. Mary's University College, Belfast. He can be contacted at [email protected].
Ivor Spence is with Queen's University of Belfast. He can be contacted at [email protected].