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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I followed the teachings of the following articles:
Samek, C/C++ Users Journal, 2003)
in C++ (Pedro Guerreiro, TOOLS, 2001)
What I ultimately applied was pretty much Samek’s approach. Just creating macros for REQUIRE, ENSURE, CHECK and INVARIANT (based on the existing
assertmacro) 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?.