Chris@16: // Chris@16: // boost/assert.hpp - BOOST_ASSERT(expr) Chris@16: // BOOST_ASSERT_MSG(expr, msg) Chris@16: // BOOST_VERIFY(expr) Chris@16: // Chris@16: // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. Chris@16: // Copyright (c) 2007 Peter Dimov Chris@16: // Copyright (c) Beman Dawes 2011 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // Note: There are no include guards. This is intentional. Chris@16: // Chris@16: // See http://www.boost.org/libs/utility/assert.html for documentation. Chris@16: // Chris@16: Chris@16: // Chris@16: // Stop inspect complaining about use of 'assert': Chris@16: // Chris@16: // boostinspect:naassert_macro Chris@16: // Chris@16: Chris@16: //--------------------------------------------------------------------------------------// Chris@16: // BOOST_ASSERT // Chris@16: //--------------------------------------------------------------------------------------// Chris@16: Chris@16: #undef BOOST_ASSERT Chris@16: Chris@16: #if defined(BOOST_DISABLE_ASSERTS) Chris@16: Chris@16: # define BOOST_ASSERT(expr) ((void)0) Chris@16: Chris@16: #elif defined(BOOST_ENABLE_ASSERT_HANDLER) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: void assertion_failed(char const * expr, Chris@16: char const * function, char const * file, long line); // user defined Chris@16: } // namespace boost Chris@16: Chris@16: #define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \ Chris@16: ? ((void)0) \ Chris@16: : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) Chris@16: Chris@16: #else Chris@16: # include // .h to support old libraries w/o - effect is the same Chris@16: # define BOOST_ASSERT(expr) assert(expr) Chris@16: #endif Chris@16: Chris@16: //--------------------------------------------------------------------------------------// Chris@16: // BOOST_ASSERT_MSG // Chris@16: //--------------------------------------------------------------------------------------// Chris@16: Chris@16: # undef BOOST_ASSERT_MSG Chris@16: Chris@16: #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) Chris@16: Chris@16: #define BOOST_ASSERT_MSG(expr, msg) ((void)0) Chris@16: Chris@16: #elif defined(BOOST_ENABLE_ASSERT_HANDLER) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: void assertion_failed_msg(char const * expr, char const * msg, Chris@16: char const * function, char const * file, long line); // user defined Chris@16: } // namespace boost Chris@16: Chris@16: #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \ Chris@16: ? ((void)0) \ Chris@16: : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) Chris@16: Chris@16: #else Chris@16: #ifndef BOOST_ASSERT_HPP Chris@16: #define BOOST_ASSERT_HPP Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // IDE's like Visual Studio perform better if output goes to std::cout or Chris@16: // some other stream, so allow user to configure output stream: Chris@16: #ifndef BOOST_ASSERT_MSG_OSTREAM Chris@16: # define BOOST_ASSERT_MSG_OSTREAM std::cerr Chris@16: #endif Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace assertion Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: // Note: The template is needed to make the function non-inline and avoid linking errors Chris@16: template< typename CharT > Chris@16: BOOST_NOINLINE void assertion_failed_msg(CharT const * expr, char const * msg, char const * function, Chris@16: char const * file, long line) Chris@16: { Chris@16: BOOST_ASSERT_MSG_OSTREAM Chris@16: << "***** Internal Program Error - assertion (" << expr << ") failed in " Chris@16: << function << ":\n" Chris@16: << file << '(' << line << "): " << msg << std::endl; Chris@16: #ifdef UNDER_CE Chris@16: // The Windows CE CRT library does not have abort() so use exit(-1) instead. Chris@16: std::exit(-1); Chris@16: #else Chris@16: std::abort(); Chris@16: #endif Chris@16: } Chris@16: } // detail Chris@16: } // assertion Chris@16: } // detail Chris@16: #endif Chris@16: Chris@16: #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \ Chris@16: ? ((void)0) \ Chris@16: : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \ Chris@16: BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) Chris@16: #endif Chris@16: Chris@16: //--------------------------------------------------------------------------------------// Chris@16: // BOOST_VERIFY // Chris@16: //--------------------------------------------------------------------------------------// Chris@16: Chris@16: #undef BOOST_VERIFY Chris@16: Chris@16: #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) Chris@16: Chris@16: # define BOOST_VERIFY(expr) ((void)(expr)) Chris@16: Chris@16: #else Chris@16: Chris@16: # define BOOST_VERIFY(expr) BOOST_ASSERT(expr) Chris@16: Chris@16: #endif