diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index b6f2f268..7a8304ea 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include +#include #include "config.hpp" #include "log.hpp" @@ -258,9 +259,18 @@ inline void assert_always( * @param print - function providing information string to print in case the assertion fails. * @param source_location - location of the assert() invocation in the source code. */ +// The condition_type template parameter and the SFINAE constraint make sure this overload is only +// selected for scalar conditions (bool, integers, pointers, enums). Class types are excluded: +// lambdas, smart pointers and std::function have their own overloads, and in Objective-C++ +// lambdas are implicitly convertible to bool (via a block pointer), which would make the +// condition_checker overload ambiguous for them. #ifdef DEBUG +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t>>> inline void assert( - bool condition, + condition_type condition, const std::function& print, const utki::source_location& source_location # if CFG_CPP >= 20 @@ -277,8 +287,12 @@ inline void assert( #else +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t>>> inline void assert( - bool, + condition_type, const std::function&, const utki::source_location& # if CFG_CPP >= 20 @@ -332,8 +346,12 @@ inline void assert( * @param condition - condition to check for being true. * @param source_location - location of the assert() invocation in the source code. */ +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t>>> inline void assert( - bool condition, + condition_type condition, const utki::source_location& source_location #if CFG_CPP >= 20 = std_source_location::current()