summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-03-22 14:25:00 +0000
committerArne Juul <arnej@verizonmedia.com>2021-03-22 14:25:00 +0000
commit0f9e7d85ee3972f845223ed9048817ba251be4be (patch)
tree7275518afc862b229cce175ca79248c7040d9f65 /vespalib
parentda2963997c87c3ad9e5423fbbe951f0eb035701a (diff)
use VESPA_STRINGIZE
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/require.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/vespalib/src/vespa/vespalib/util/require.h b/vespalib/src/vespa/vespalib/util/require.h
index ef3efd3d6e2..c666a06c8d6 100644
--- a/vespalib/src/vespa/vespalib/util/require.h
+++ b/vespalib/src/vespa/vespalib/util/require.h
@@ -2,6 +2,7 @@
#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