From 3d89b33c5f01465372f293abd970160f652824ef Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 5 Oct 2022 16:39:22 +0200 Subject: a --- compat/assert.hpp | 49 ++++++++++++++++++++++++++----------------------- compat/defs.hpp | 9 --------- 2 files changed, 26 insertions(+), 32 deletions(-) (limited to 'compat') diff --git a/compat/assert.hpp b/compat/assert.hpp index 89c89c64..a9dbe0bc 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -1,20 +1,22 @@ #pragma once +#include "defs.hpp" #include #include #include namespace Magnum::Examples::detail { -template -constexpr inline void abort(const char* fmt, Xs... xs) +template +constexpr void abort(const char (&fmt)[N], Xs... xs) { - if (std::is_constant_evaluated()) { + if (std::is_constant_evaluated()) + throw "aborting"; + else { std::fprintf(stderr, fmt, xs...); std::putc('\n', stderr); std::fflush(stderr); std::abort(); - } else - throw "aborting"; + } } } // namespace Magnum::Examples::detail @@ -22,28 +24,29 @@ constexpr inline void abort(const char* fmt, Xs... xs) namespace Magnum::Examples { #define ABORT(...) \ - do { \ - if (std::is_constant_evaluated()) \ - throw "aborting"; \ - else \ - ::Magnum::Examples::detail:: \ - abort("aborting at %s:%d", __FILE__, __LINE__); \ + do { \ + if (std::is_constant_evaluated()) \ + throw "aborting"; \ + else \ + ::Magnum::Examples::detail:: \ + abort("%s: aborting at %s:%d", FUNCTION_NAME, __FILE__, __LINE__); \ } while (false) -#define ASSERT(expr) \ - do { \ - if (!(expr)) { \ - ABORT("assertion failed: '%s' in %s:%d", \ - #expr, __FILE__, __LINE__); \ - } \ +#define ASSERT(expr) \ + do { \ + if (!(expr)) { \ + ::Magnum::Examples::detail:: \ + abort("%s: assertion failed: '%s' in %s:%d", \ + FUNCTION_NAME, #expr, __FILE__, __LINE__); \ + } \ } while(false) -#define GAME_DEBUG_OUT(pfx, ...) ([&]() { \ - if constexpr (sizeof((pfx)) > 1) \ - std::fputs((pfx), stderr); \ - std::fprintf(stderr, __VA_ARGS__); \ - std::fputs("\n", stderr); \ - std::fflush(stderr); \ +#define GAME_DEBUG_OUT(pfx, ...) ([&]() { \ + if constexpr (sizeof((pfx)) > 1) \ + std::fputs((pfx), stderr); \ + std::fprintf(stderr, __VA_ARGS__); \ + std::fputs("\n", stderr); \ + std::fflush(stderr); \ }()) #define WARN(...) GAME_DEBUG_OUT("warning: ", __VA_ARGS__) diff --git a/compat/defs.hpp b/compat/defs.hpp index bde7d7e3..cd2e13cb 100644 --- a/compat/defs.hpp +++ b/compat/defs.hpp @@ -1,13 +1,4 @@ #pragma once -#include -#include - -namespace Magnum::Examples { - -using size_t = std::size_t; -using ssize_t = std::common_type_t>; - -} // namespace Magnum::Examples #ifdef _MSC_VER # define FUNCTION_NAME __FUNCSIG__ -- cgit v1.2.3