2 // Copyright (C) 2008-2018 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0 (see accompanying
4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
7 #include <boost/contract.hpp>
20 // Contract for a for-loop (same for while- and all other loops).
21 for(std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++i) {
22 boost::contract::old_ptr<int> old_total = BOOST_CONTRACT_OLDOF(total);
23 boost::contract::check c = boost::contract::function()
25 BOOST_CONTRACT_ASSERT(
26 total < std::numeric_limits<int>::max() - *i);
29 BOOST_CONTRACT_ASSERT(total == *old_total + *i);
33 total += *i; // For-loop body.