assert.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2007 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Boost.MultiArray Library
  6. // Authors: Ronald Garcia
  7. // Jeremy Siek
  8. // Andrew Lumsdaine
  9. // See http://www.boost.org/libs/multi_array for documentation.
  10. //
  11. // Using the BOOST.ASSERT mechanism to replace library assertions
  12. // with exceptions
  13. //
  14. #include <boost/core/lightweight_test.hpp>
  15. #define BOOST_ENABLE_ASSERT_HANDLER
  16. #include <boost/multi_array.hpp> // includes assert.hpp
  17. #include <stdexcept>
  18. namespace boost {
  19. void assertion_failed(char const* expr, char const* function,
  20. char const* file, long line) {
  21. throw std::runtime_error(expr);
  22. }
  23. void assertion_failed_msg(char const * expr, char const * msg,
  24. char const * function,
  25. char const * file, long line) {
  26. throw std::runtime_error(msg);
  27. }
  28. } // namespace boost
  29. using namespace boost;
  30. int
  31. main() {
  32. typedef multi_array<int,2> array_t;
  33. array_t A(extents[2][2]);
  34. array_t B(extents[3][3]);
  35. try {
  36. A = B;
  37. BOOST_ERROR("did not throw an exception");
  38. } catch (std::runtime_error&) {
  39. //...all good
  40. }
  41. return boost::report_errors();
  42. }