|
@@ -1,15 +1,7 @@
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
-#include <iostream>
|
|
|
|
|
-#include <sstream>
|
|
|
|
|
-
|
|
|
|
|
-#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
|
-#define JVALIDATE_LIKELY(x) __builtin_expect(!!(x), 1)
|
|
|
|
|
-#define JVALIDATE_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
|
|
|
-#else
|
|
|
|
|
-#define JVALIDATE_LIKELY(x) (x)
|
|
|
|
|
-#define JVALIDATE_UNLIKELY(x) (x)
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+#include <iostream> // IWYU pragma: keep
|
|
|
|
|
+#include <sstream> // IWYU pragma: keep
|
|
|
|
|
|
|
|
#if defined(JVALIDATE_USE_EXCEPTIONS)
|
|
#if defined(JVALIDATE_USE_EXCEPTIONS)
|
|
|
/**
|
|
/**
|
|
@@ -58,7 +50,7 @@
|
|
|
* output chain (e.g. `"unsupported index " << i << ", valid items " << items`).
|
|
* output chain (e.g. `"unsupported index " << i << ", valid items " << items`).
|
|
|
*/
|
|
*/
|
|
|
#define EXPECT_T(condition, extype, message) \
|
|
#define EXPECT_T(condition, extype, message) \
|
|
|
- if (JVALIDATE_UNLIKELY(!(condition))) { \
|
|
|
|
|
|
|
+ if (!(condition)) [[unlikely]] { \
|
|
|
JVALIDATE_THROW(extype, message); \
|
|
JVALIDATE_THROW(extype, message); \
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -81,19 +73,3 @@
|
|
|
* If the condition is FALSE, then the other params are used to produce errors.
|
|
* If the condition is FALSE, then the other params are used to produce errors.
|
|
|
*/
|
|
*/
|
|
|
#define EXPECT(condition) EXPECT_M(condition, #condition " at " __FILE__ ":" << __LINE__)
|
|
#define EXPECT(condition) EXPECT_M(condition, #condition " at " __FILE__ ":" << __LINE__)
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @brief Assert a certain pre/post-condition is true, else return the default
|
|
|
|
|
- * expression (or void).
|
|
|
|
|
- *
|
|
|
|
|
- * @param condition A boolean or boolean-like expression that should be TRUE.
|
|
|
|
|
- * If the condition is FALSE, then the other params are used to produce errors.
|
|
|
|
|
- *
|
|
|
|
|
- * @param ... Zero or One arguments representing the return value if the
|
|
|
|
|
- * condition is FALSE. Zero arguments is equivalent to `return void();`, which
|
|
|
|
|
- * doesn't need to be explicitly stated.
|
|
|
|
|
- */
|
|
|
|
|
-#define RETURN_UNLESS(condition, ...) \
|
|
|
|
|
- if (JVALIDATE_UNLIKELY(!(condition))) { \
|
|
|
|
|
- return __VA_ARGS__; \
|
|
|
|
|
- }
|
|
|