Is there any library that aids in implementing the design by contract principle in a C++ application?
In particular, I'm looking for a library that facilities the usage of the principle, something like this.
I followed the teachings of the following articles:
What I ultimately applied was pretty much Samek's approach. Just creating macros for REQUIRE, ENSURE, CHECK and INVARIANT (based on the existing assert
macro) was very useful. Of course it's not as good as native language support but anyway, it allows you to get most of the practical value from the technique.
As for libraries, I don't think that it pays to use one, because one important value of the assertion mechanism is its simplicity.
For the difference between debug and production code, see When should assertions stay in production code?.
Simplest?
Assert statements at the start of your function to test your requirements. Assert statements at the end of your function to test your results.
Yes, it's crude, its not a big system, but its simplicity makes it versatile and portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With