exception.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #ifndef BOOST_CONTRACT_DETAIL_EXCEPTION_HPP_
  2. #define BOOST_CONTRACT_DETAIL_EXCEPTION_HPP_
  3. // Copyright (C) 2008-2019 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/config.hpp>
  8. #include <exception>
  9. namespace boost { namespace contract { namespace detail {
  10. // Using this instead of std::uncaught_exception() because
  11. // std::uncaught_exception will be removed in C++20.
  12. inline bool uncaught_exception() BOOST_NOEXCEPT {
  13. // Alternatively, this could just return `boost::core::uncaught_exceptions()
  14. // > 0` but that emulates the exception count which is not needed by this
  15. // lib (the implementation below is simpler and could be faster).
  16. #ifdef __cpp_lib_uncaught_exceptions
  17. return std::uncaught_exceptions() > 0;
  18. #else
  19. return std::uncaught_exception();
  20. #endif
  21. }
  22. } } } // namespace
  23. #endif // #include guard