If you don't mind using C++0x features, you could implement preconditions and postconditions using lambdas and RAII.
A simple example of postcondition:
struct __call_on_destructor {
std::tr1::function<void()> _function;
template<class Func> inline __call_on_destructor(Func func) {
_function = func;
}
inline ~__call_on_destructor() {
_function();
}
};
#define on_scope_exit(function) \
__call_on_destructor PP_UNIQUE_LABEL(on_exit) (function)
#define ensures(expression) \
on_scope_exit([&] () { assert(expression); })
Similarly, you could implement preconditions and invariants.
The code was taken from an extremely simple C++0x Contracts library.