1 2 #ifndef BOOST_CONTRACT_DETAIL_ASSERT_HPP_ 3 #define BOOST_CONTRACT_DETAIL_ASSERT_HPP_ 4 5 // Copyright (C) 2008-2018 Lorenzo Caminiti 6 // Distributed under the Boost Software License, Version 1.0 (see accompanying 7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). 8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html 9 10 #include <boost/contract/core/exception.hpp> 11 #include <boost/contract/detail/noop.hpp> 12 #include <boost/preprocessor/stringize.hpp> 13 14 // In detail because used by both ASSERT and CHECK. 15 // Use ternary operator `?:` and no trailing `;` here to allow `if(...) ASSERT( 16 // ...); else ...` (won't compile if expands using an if statement instead even 17 // if wrapped by {}, and else won't compile if expands trailing `;`). 18 #define BOOST_CONTRACT_DETAIL_ASSERT(cond) \ 19 /* no if-statement here */ \ 20 ((cond) ? \ 21 BOOST_CONTRACT_DETAIL_NOOP \ 22 : \ 23 throw boost::contract::assertion_failure( \ 24 __FILE__, __LINE__, BOOST_PP_STRINGIZE(cond)) \ 25 ) /* no ; here */ 26 27 #endif // #include guard 28 29