1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
#ifndef ASSERT_HPP
#define ASSERT_HPP

#include <iostream>

#ifdef NDEBUG
#define ASSERT(condition) ((void)0)
#else
#define ASSERT(condition) (safe_assert((condition), #condition, \
   __FILE__, __LINE__, __func__))
#endif

inline void safe_assert(bool condition, const char* condition_text,
      const char* filename, int line, const char* function) noexcept {
   if (!condition) {
      try {
	 std::cerr << "Assertion failed: " << condition_text <<
	    ", file " << filename << ", line " << line <<
	    ", function " << function << std::endl;
      } catch (...) {
	 /* we want to keep the noexcept promise */
      }
      std::abort();
   }
}

#endif