1 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 6 7 //[n1962_sum 8 #include <boost/contract.hpp> 9 #include <cassert> 10 sum(int count,int * array)11int sum(int count, int* array) { 12 int result; 13 boost::contract::check c = boost::contract::function() 14 .precondition([&] { 15 BOOST_CONTRACT_ASSERT(count % 4 == 0); 16 }) 17 ; 18 19 result = 0; 20 for(int i = 0; i < count; ++i) result += array[i]; 21 return result; 22 } 23 main()24int main() { 25 int a[4] = {1, 2, 3, 4}; 26 assert(sum(4, a) == 10); 27 return 0; 28 } 29 //] 30 31