From 9356e8ccb501ec60b4d89dae6a9edac3424b263c Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 3 Dec 2020 11:18:27 +0100 Subject: [PATCH] config: reintroduce ENTT_DISABLE_ASSERT (close #599) --- docs/md/config.md | 16 ++++++++++++---- src/entt/config/config.h | 5 ++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/md/config.md b/docs/md/config.md index a612880f4..809d92781 100644 --- a/docs/md/config.md +++ b/docs/md/config.md @@ -12,6 +12,7 @@ * [ENTT_ID_TYPE](#entt_id_type) * [ENTT_PAGE_SIZE](#entt_page_size) * [ENTT_ASSERT](#entt_assert) + * [ENTT_DISABLE_ASSERT](#entt_disable_assert) * [ENTT_NO_ETO](#entt_no_eto) * [ENTT_STANDARD_CPP](#entt_standard_cpp) @@ -71,10 +72,17 @@ all case, the chosen value **must** be a power of 2. For performance reasons, `EnTT` doesn't use exceptions or any other control structures. In fact, it offers many features that result in undefined behavior if not used correctly.
-To get around this, the library relies on a lot of `assert`s for the purpose of -detecting errors in debug builds. However, these assertions may in turn affect -performance to an extent.
-This option is meant to disable all controls. +To get around this, the library relies on a lot of asserts for the purpose of +detecting errors in debug builds. By default, it uses `assert` internally, but +users are allowed to overwrite its behavior by setting this variable. + +### ENTT_DISABLE_ASSERT + +Assertions may in turn affect performance to an extent when enabled. Whether +`ENTT_ASSERT` is redefined or not, all asserts can be disabled at once by means +of this definition.
+Note that `ENTT_DISABLE_ASSERT` takes precedence over the redefinition of +`ENTT_ASSERT` and is therefore meant to disable all controls no matter what. ## ENTT_NO_ETO diff --git a/src/entt/config/config.h b/src/entt/config/config.h index 59ccf9b76..67c00cabe 100644 --- a/src/entt/config/config.h +++ b/src/entt/config/config.h @@ -26,7 +26,10 @@ #endif -#ifndef ENTT_ASSERT +#ifdef ENTT_DISABLE_ASSERT +# undef ENTT_ASSERT +# define ENTT_ASSERT(...) (void(0)) +#elif !defined ENTT_ASSERT # include # define ENTT_ASSERT(condition) assert(condition) #endif