assert.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // boost/assert.hpp - BOOST_ASSERT(expr)
  3. // BOOST_ASSERT_MSG(expr, msg)
  4. // BOOST_VERIFY(expr)
  5. // BOOST_VERIFY_MSG(expr, msg)
  6. // BOOST_ASSERT_IS_VOID
  7. //
  8. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
  9. // Copyright (c) 2007, 2014 Peter Dimov
  10. // Copyright (c) Beman Dawes 2011
  11. // Copyright (c) 2015 Ion Gaztanaga
  12. //
  13. // Distributed under the Boost Software License, Version 1.0.
  14. // See accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt
  16. //
  17. // Note: There are no include guards. This is intentional.
  18. //
  19. // See http://www.boost.org/libs/assert/assert.html for documentation.
  20. //
  21. //
  22. // Stop inspect complaining about use of 'assert':
  23. //
  24. // boostinspect:naassert_macro
  25. //
  26. //
  27. // BOOST_ASSERT, BOOST_ASSERT_MSG, BOOST_ASSERT_IS_VOID
  28. //
  29. #undef BOOST_ASSERT
  30. #undef BOOST_ASSERT_MSG
  31. #undef BOOST_ASSERT_IS_VOID
  32. #if defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) )
  33. # define BOOST_ASSERT(expr) ((void)0)
  34. # define BOOST_ASSERT_MSG(expr, msg) ((void)0)
  35. # define BOOST_ASSERT_IS_VOID
  36. #elif defined(BOOST_ENABLE_ASSERT_HANDLER) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG) )
  37. #include <boost/config.hpp> // for BOOST_LIKELY
  38. #include <boost/current_function.hpp>
  39. namespace boost
  40. {
  41. void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined
  42. void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); // user defined
  43. } // namespace boost
  44. #define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
  45. #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
  46. #else
  47. # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
  48. # define BOOST_ASSERT(expr) assert(expr)
  49. # define BOOST_ASSERT_MSG(expr, msg) assert((expr)&&(msg))
  50. #if defined(NDEBUG)
  51. # define BOOST_ASSERT_IS_VOID
  52. #endif
  53. #endif
  54. //
  55. // BOOST_VERIFY, BOOST_VERIFY_MSG
  56. //
  57. #undef BOOST_VERIFY
  58. #undef BOOST_VERIFY_MSG
  59. #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
  60. # define BOOST_VERIFY(expr) ((void)(expr))
  61. # define BOOST_VERIFY_MSG(expr, msg) ((void)(expr))
  62. #else
  63. # define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
  64. # define BOOST_VERIFY_MSG(expr, msg) BOOST_ASSERT_MSG(expr,msg)
  65. #endif