mirror of
https://github.com/boostorg/contract.git
synced 2026-01-28 07:02:16 +00:00
completed first revised draft of docs
This commit is contained in:
21
example/features/free_function.cpp
Normal file
21
example/features/free_function.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
//[free_function
|
||||
#include <boost/contract.hpp>
|
||||
|
||||
int inc(int& x) {
|
||||
int result;
|
||||
boost::shared_ptr<int const> old_x = BOOST_CONTRACT_OLDOF(x);
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x < std::numberic_limits<int>::max());
|
||||
})
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x == *old_x + 1);
|
||||
BOOST_CONTRACT_ASSERT(result == *old_x);
|
||||
})
|
||||
;
|
||||
|
||||
return result = x++; // Function body.
|
||||
}
|
||||
//]
|
||||
|
||||
Reference in New Issue
Block a user