From 2e36dd2d581556710dfcde9ee6bd16fd5b65ca0e Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sun, 3 Oct 2021 02:52:54 -0400 Subject: [PATCH] error: introduce THROW_CHECK4, the long-awaited sequel to THROW_CHECK3 Sometimes we need to check constraints on 4 variables at once. It would be nice if variadic macros in C++ were also polymorphic. Signed-off-by: Zygo Blaxell --- include/crucible/error.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/crucible/error.h b/include/crucible/error.h index 1cfc0fa..6952dce 100644 --- a/include/crucible/error.h +++ b/include/crucible/error.h @@ -126,6 +126,13 @@ namespace crucible { } \ } while(0) +#define THROW_CHECK4(type, value1, value2, value3, value4, expr) do { \ + if (!(expr)) { \ + THROW_ERROR(type, #value1 << " = " << (value1) << ", " #value2 << " = " << (value2) << ", " #value3 << " = " << (value3) << ", " #value4 << " = " << (value4) \ + << " failed constraint check (" << #expr << ")"); \ + } \ +} while(0) + #define THROW_CHECK_BIN_OP(type, value1, op, value2) do { \ if (!((value1) op (value2))) { \ THROW_ERROR(type, "failed constraint check " << #value1 << " (" << (value1) << ") " << #op << " " << #value2 << " (" << (value2) << ")"); \