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 // Test assertion error when operations to check them missing (e.g., `==`). 8 9 #include <boost/contract/function.hpp> 10 #include <boost/contract/check.hpp> 11 #include <boost/contract/assert.hpp> 12 #include <vector> 13 14 template<typename T> push_back(std::vector<T> & vect,T const & value)15void push_back(std::vector<T>& vect, T const& value) { 16 boost::contract::check c = boost::contract::function() 17 .postcondition([&] { 18 BOOST_CONTRACT_ASSERT(vect.back() == value); // Error (j has no ==). 19 #ifdef BOOST_CONTRACT_NO_ALL 20 #error "force error if no contracts (ASSERT expands to nothing)" 21 #endif 22 }) 23 ; 24 vect.push_back(value); 25 } 26 27 struct j { // Type without operator==. jj28 explicit j(int /* i */) {} 29 }; 30 main()31int main() { 32 std::vector<int> vi; 33 push_back(vi, 123); 34 35 j jj(456); 36 std::vector<j> vj; 37 push_back(vj, jj); 38 39 return 0; 40 } 41 42