started advanced topics section in the docs

This commit is contained in:
Lorenzo Caminiti
2015-06-27 08:03:34 -07:00
parent be3a974847
commit 2fb2ddc367
125 changed files with 2979 additions and 3114 deletions

25
example/n1962/sqrt.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <boost/contract.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cmath>
double mysqrt(double x, double precision = 1e-6) {
double result;
auto c = boost::contract::function()
.precondition([&] {
BOOST_CONTRACT_ASSERT(x >= 0.0);
})
.postcondition([&] {
BOOST_CONTRACT_ASSERT(fabs(result * result - x) <= precision);
})
;
return result = sqrt(x);
}
int main() {
double const precision = 1e-6;
BOOST_TEST(fabs(mysqrt(4.0, precision) - 2.0) <= precision);
return boost::report_errors();
}