Extend assert macros

This commit is contained in:
Piotr Wójcik 2025-06-04 14:45:02 +02:00
commit 0c3ae5c7fc

View file

@ -4,12 +4,14 @@
#include <boost/preprocessor/facilities/empty.hpp> #include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/facilities/overload.hpp> #include <boost/preprocessor/facilities/overload.hpp>
#include <string>
#include <string_view> #include <string_view>
[[noreturn]] void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error = ""); [[noreturn]] void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error = "");
#define release_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true) #define release_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true)
#define release_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true, error_msg) #define release_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true, error_msg)
#define release_assert_3(check, error_msg, extra) (check) ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true, std::string (error_msg) + " (" + (extra) + ")")
#if !BOOST_PP_VARIADICS_MSVC #if !BOOST_PP_VARIADICS_MSVC
#define release_assert(...) \ #define release_assert(...) \
BOOST_PP_OVERLOAD (release_assert_, __VA_ARGS__) \ BOOST_PP_OVERLOAD (release_assert_, __VA_ARGS__) \
@ -23,6 +25,7 @@
#else #else
#define debug_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false) #define debug_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false)
#define debug_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false, error_msg) #define debug_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false, error_msg)
#define debug_assert_3(check, error_msg, extra) (check) ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false, std::string (error_msg) + " (" + (extra) + ")")
#if !BOOST_PP_VARIADICS_MSVC #if !BOOST_PP_VARIADICS_MSVC
#define debug_assert(...) \ #define debug_assert(...) \
BOOST_PP_OVERLOAD (debug_assert_, __VA_ARGS__) \ BOOST_PP_OVERLOAD (debug_assert_, __VA_ARGS__) \