assert.hpp 1.1 KB

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