Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/utki/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE.
#include <functional>
#include <memory>
#include <sstream>
#include <type_traits>

#include "config.hpp"
#include "log.hpp"
Expand Down Expand Up @@ -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<!std::is_class_v<std::decay_t<condition_type>>>>
inline void assert(
bool condition,
condition_type condition,
const std::function<void(std::ostream&)>& print,
const utki::source_location& source_location
# if CFG_CPP >= 20
Expand All @@ -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<!std::is_class_v<std::decay_t<condition_type>>>>
inline void assert(
bool,
condition_type,
const std::function<void(std::ostream&)>&,
const utki::source_location&
# if CFG_CPP >= 20
Expand Down Expand Up @@ -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<!std::is_class_v<std::decay_t<condition_type>>>>
inline void assert(
bool condition,
condition_type condition,
const utki::source_location& source_location
#if CFG_CPP >= 20
= std_source_location::current()
Expand Down
Loading