diff --git a/default.config b/default.config index 6773143..8a2fae2 100644 --- a/default.config +++ b/default.config @@ -80,7 +80,7 @@ case "$TASK" in ;; # creates executable with debug info and no optimizations build_exec_dbg) - C_ARGS="-O0 -g" + C_ARGS="-O0 -g -DDEBUG=1" CPP_ARGS="$C_ARGS" LINKER_ARGS="$CPP_ARGS $LINKER_LIBS" PRE_TASK_SCRIPT=tasks/pre_build.sh diff --git a/src/UsefulException.hpp b/src/UsefulException.hpp index 25b4217..ae6f668 100644 --- a/src/UsefulException.hpp +++ b/src/UsefulException.hpp @@ -17,3 +17,11 @@ public: virtual char const* what() const noexcept; }; + +#if DEBUG == 1 +/// Use this macro to find bugs in debug build. Release build could be compiled without asserts. Define DEBUG=1 to enable assert compilation. + #define assert(EXPR, ERRMSG) if(!EXPR) throw UsefulException(ERRMSG); +#else +/// Use this macro to find bugs in debug build. Release build could be compiled without asserts. Define DEBUG=1 to enable assert compilation. + #define assert(EXPR, ERRMSG) EXPR +#endif diff --git a/src/format.cpp b/src/format.cpp index 4e0f47d..15c05fc 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -4,7 +4,7 @@ #include "UsefulException.hpp" #include "../dependencies/kerep/src/base/base.h" -std::string format(const std::string format_str, size_t args_count, ...){ +std::string _format(const std::string format_str, size_t args_count, ...){ va_list vl; va_start(vl, args_count); std::stringstream ss; diff --git a/src/format.hpp b/src/format.hpp index 5432382..acb41f6 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -1,5 +1,7 @@ #pragma once #include +#include "../dependencies/kerep/src/base/std.h" -std::string format(const std::string format_str, size_t args_count, ...); +std::string _format(const std::string format_str, size_t args_count, ...); +#define format(FORMAT_STR, ARGS...) _format(FORMAT_STR, count_args(ARGS) ,##ARGS)