use VESPA_STRINGIZE
#pragma once
+#include "macro.h"
#include <iostream>
#include <vespa/vespalib/util/exception.h>
@@ -26,19 +27,28 @@ void handle_require_eq_failure [[noreturn]] (const A& a, const B& b, const char
throw_require_failed(description, file, line);
}
-#ifndef __STRING
-#define __STRING(x) #x
-#endif
-
+/**
+ * Require a condition to be true.
+ * If the requirement is not met, prints a nice message and throws
+ * an exception. Use instead of assert() or ASSERT_TRUE().
+ **/
#define REQUIRE(...) \
(__VA_ARGS__) ? vespalib::handle_require_success() : \
- vespalib::handle_require_failure(__STRING(__VA_ARGS__), \
+ vespalib::handle_require_failure(VESPA_STRINGIZE(__VA_ARGS__), \
__FILE__, __LINE__)
+/**
+ * Require two values to be equal.
+ * If the requirement is not met, prints a nice message and throws
+ * an exception. Use instead of assert() or ASSERT_TRUE().
+ * Note: both operator== and operator<< (to stream) must be implemented
+ * for the value types.
+ **/
#define REQUIRE_EQ(a, b) \
(a == b) ? vespalib::handle_require_success() : \
- vespalib::handle_require_eq_failure(a, b, __STRING(a), __STRING(b), \
- __STRING(a) " == " __STRING(b), \
+ vespalib::handle_require_eq_failure(a, b, \
+ VESPA_STRINGIZE(a), VESPA_STRINGIZE(b), \
+ VESPA_STRINGIZE(a) " == " VESPA_STRINGIZE(b), \
__FILE__, __LINE__)
} // namespace
