2
0

assertx.hpp 758 B

123456789101112131415161718192021222324252627
  1. #ifndef ASSERTX_HPP_INCLUDED
  2. #define ASSERTX_HPP_INCLUDED
  3. #include <cassert>
  4. /* The compiler often warns you if you give a function formal parameter a
  5. name, but don't use it. But because assert() disappears when doing an
  6. optimized build, the compiler doesn't recognize your reference to the
  7. parameter in the assert() argument. To avoid the bogus warning in
  8. this case, we have ASSERT_ONLY_ARG(), which declares a name for a
  9. formal parameter for purposes of assert() only. In cases where an
  10. assert() would disappear, ASSERT_ONLY_ARG() disappears too.
  11. E.g.
  12. void foo(int const ASSERT_ONLY_ARG(arg1)) {
  13. assert(arg1 > 0);
  14. }
  15. */
  16. #ifdef NDEBUG
  17. #define ASSERT_ONLY_ARG(x)
  18. #else
  19. #define ASSERT_ONLY_ARG(x) x
  20. #endif
  21. #endif