ZeroErr
Loading...
Searching...
No Matches
assert.h File Reference
#include "zeroerr/internal/config.h"
#include "zeroerr/format.h"
#include "zeroerr/internal/debugbreak.h"
#include "zeroerr/internal/decomposition.h"
#include "zeroerr/print.h"
#include <cstdint>
#include <exception>
#include <iostream>
Include dependency graph for assert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  zeroerr::assert_info
 This is a one-byte assert info struct, which is used to collect the meta info of an assertion. More...
 
struct  zeroerr::AssertionData
 AssertionData is a struct that contains all the information of an assertion. It will be thrown as an exception when the assertion failed. More...
 
struct  zeroerr::detail::context_helper< T, true >
 
struct  zeroerr::detail::context_helper< T, false >
 

Namespaces

namespace  ZEROERR_CLANG_SUPPRESS_WARNING_POP
 
namespace  zeroerr
 
namespace  zeroerr::detail
 

Macros

#define ZEROERR_G_CONTEXT_SCOPE(x)
 
#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, ...)
 Default printer for assertion messages.
 
#define ZEROERR_PRINT_ASSERT(cond, level, pattern, ...)
 
#define ZEROERR_ASSERT_EXP(cond, level, expect_throw, is_false, ...)
 
#define ZEROERR_ASSERT_CMP(lhs, op, rhs, level, expect_throw, is_false, ...)
 
#define ZEROERR_CHECK(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, no_throw, false, __VA_ARGS__))
 
#define ZEROERR_CHECK_NOT(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, no_throw, true, __VA_ARGS__))
 
#define ZEROERR_CHECK_THROWS(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, throws, false, __VA_ARGS__))
 
#define ZEROERR_REQUIRE(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, no_throw, false, __VA_ARGS__))
 
#define ZEROERR_REQUIRE_NOT(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, no_throw, true, __VA_ARGS__))
 
#define ZEROERR_REQUIRE_THROWS(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, throws, false, __VA_ARGS__))
 
#define ZEROERR_ASSERT(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, no_throw, false, __VA_ARGS__))
 
#define ZEROERR_ASSERT_NOT(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, no_throw, true, __VA_ARGS__))
 
#define ZEROERR_ASSERT_THROWS(cond, ...)   ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, throws, false, __VA_ARGS__))
 
#define CHECK(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_NOT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_NOT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_THROWS(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_THROWS(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_NOT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_NOT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_THROWS(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_THROWS(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_NOT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_NOT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_THROWS(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_THROWS(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ZEROERR_CHECK_EQ(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_CHECK_NE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_CHECK_LT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_CHECK_LE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_CHECK_GT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_CHECK_GE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_EQ(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_NE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_LT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_LE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_GT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_REQUIRE_GE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_EQ(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_NE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_LT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_LE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_GT(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define ZEROERR_ASSERT_GE(lhs, rhs, ...)   ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)
 
#define CHECK_EQ(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_EQ(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_NE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_NE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_LT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_LT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_LE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_LE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_GT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_GT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define CHECK_GE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_CHECK_GE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_EQ(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_EQ(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_NE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_NE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_LT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_LT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_LE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_LE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_GT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_GT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define REQUIRE_GE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_REQUIRE_GE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_EQ(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_EQ(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_NE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_NE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_LT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_LT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_LE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_LE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_GT(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_GT(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ASSERT_GE(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_ASSERT_GE(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 

Enumerations

enum class  zeroerr::assert_level : uint8_t { zeroerr::ZEROERR_WARN_l , zeroerr::ZEROERR_ERROR_l , zeroerr::ZEROERR_FATAL_l }
 
enum class  zeroerr::assert_throw : uint8_t { zeroerr::no_throw , zeroerr::throws , zeroerr::throws_as }
 
enum class  zeroerr::assert_cmp : uint8_t {
  zeroerr::eq , zeroerr::ne , zeroerr::gt , zeroerr::ge ,
  zeroerr::lt , zeroerr::le
}
 

Variables

constexpr bool ZEROERR_CLANG_SUPPRESS_WARNING_POP::_ZEROERR_TEST_CONTEXT = false
 

Macro Definition Documentation

◆ ASSERT

◆ ASSERT_EQ

◆ ASSERT_GE

◆ ASSERT_GT

◆ ASSERT_LE

◆ ASSERT_LT

◆ ASSERT_NE

◆ ASSERT_NOT

◆ ASSERT_THROWS

◆ CHECK

◆ CHECK_EQ

◆ CHECK_GE

◆ CHECK_GT

◆ CHECK_LE

◆ CHECK_LT

◆ CHECK_NE

◆ CHECK_NOT

◆ CHECK_THROWS

◆ REQUIRE

◆ REQUIRE_EQ

◆ REQUIRE_GE

◆ REQUIRE_GT

◆ REQUIRE_LE

◆ REQUIRE_LT

◆ REQUIRE_NE

◆ REQUIRE_NOT

◆ REQUIRE_THROWS

◆ ZEROERR_ASSERT

#define ZEROERR_ASSERT (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, no_throw, false, __VA_ARGS__))

◆ ZEROERR_ASSERT_CMP

#define ZEROERR_ASSERT_CMP (   lhs,
  op,
  rhs,
  level,
  expect_throw,
  is_false,
  ... 
)
Value:
zeroerr::assert_info info{zeroerr::assert_level::ZEROERR_CAT(level, _l), \
zeroerr::assert_throw::expect_throw, is_false}; \
\
print.isQuoted = false; \
zeroerr::AssertionData assertion_data(__FILE__, __LINE__, #lhs " " #op " " #rhs, info); \
try { \
assertion_data.setResult({(lhs)op(rhs), print(lhs, #op, rhs)}); \
} catch (const std::exception& e) { \
assertion_data.setException(e); \
} \
decltype(_ZEROERR_TEST_CONTEXT), \
std::is_same<decltype(_ZEROERR_TEST_CONTEXT), \
const bool>::value>::setContext(assertion_data, _ZEROERR_TEST_CONTEXT); \
ZEROERR_PRINT_ASSERT(assertion_data.passed == false, level, __VA_ARGS__); \
if (false) debug_break(); \
assertion_data(); \
ZEROERR_FUNC_SCOPE_RET(assertion_data.passed); \
} \
#define ZEROERR_FUNC_SCOPE_RET(v)
Definition config.h:118
#define ZEROERR_FUNC_SCOPE_END
Definition config.h:117
#define ZEROERR_FUNC_SCOPE_BEGIN
Definition config.h:116
constexpr bool _ZEROERR_TEST_CONTEXT
Definition assert.h:219
AssertionData is a struct that contains all the information of an assertion. It will be thrown as an ...
Definition assert.h:244
A functor class Printer for printing a value of any type.
Definition print.h:63
bool isQuoted
Definition print.h:106
This is a one-byte assert info struct, which is used to collect the meta info of an assertion.
Definition assert.h:233
Definition assert.h:295

◆ ZEROERR_ASSERT_EQ

#define ZEROERR_ASSERT_EQ (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_EXP

#define ZEROERR_ASSERT_EXP (   cond,
  level,
  expect_throw,
  is_false,
  ... 
)
Value:
zeroerr::assert_info info{zeroerr::assert_level::ZEROERR_CAT(level, _l), \
zeroerr::assert_throw::expect_throw, is_false}; \
\
zeroerr::AssertionData assertion_data(__FILE__, __LINE__, #cond, info); \
try { \
assertion_data.setResult(zeroerr::ExpressionDecomposer() << cond); \
} catch (const std::exception& e) { \
assertion_data.setException(e); \
} \
decltype(_ZEROERR_TEST_CONTEXT), \
std::is_same<decltype(_ZEROERR_TEST_CONTEXT), \
const bool>::value>::setContext(assertion_data, _ZEROERR_TEST_CONTEXT); \
ZEROERR_PRINT_ASSERT(assertion_data.passed == false, level, __VA_ARGS__); \
if (false) debug_break(); \
assertion_data(); \
ZEROERR_FUNC_SCOPE_RET(assertion_data.passed); \
} \
Definition decomposition.h:183

◆ ZEROERR_ASSERT_GE

#define ZEROERR_ASSERT_GE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_GT

#define ZEROERR_ASSERT_GT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_LE

#define ZEROERR_ASSERT_LE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_LT

#define ZEROERR_ASSERT_LT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_NE

#define ZEROERR_ASSERT_NE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_FATAL, no_throw, false, __VA_ARGS__)

◆ ZEROERR_ASSERT_NOT

#define ZEROERR_ASSERT_NOT (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, no_throw, true, __VA_ARGS__))

◆ ZEROERR_ASSERT_THROWS

#define ZEROERR_ASSERT_THROWS (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_FATAL, throws, false, __VA_ARGS__))

◆ ZEROERR_CHECK

#define ZEROERR_CHECK (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, no_throw, false, __VA_ARGS__))

◆ ZEROERR_CHECK_EQ

#define ZEROERR_CHECK_EQ (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_GE

#define ZEROERR_CHECK_GE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_GT

#define ZEROERR_CHECK_GT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_LE

#define ZEROERR_CHECK_LE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_LT

#define ZEROERR_CHECK_LT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_NE

#define ZEROERR_CHECK_NE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_WARN, no_throw, false, __VA_ARGS__)

◆ ZEROERR_CHECK_NOT

#define ZEROERR_CHECK_NOT (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, no_throw, true, __VA_ARGS__))

◆ ZEROERR_CHECK_THROWS

#define ZEROERR_CHECK_THROWS (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_WARN, throws, false, __VA_ARGS__))

◆ ZEROERR_G_CONTEXT_SCOPE

#define ZEROERR_G_CONTEXT_SCOPE (   x)

◆ ZEROERR_PRINT_ASSERT

#define ZEROERR_PRINT_ASSERT (   cond,
  level,
  pattern,
  ... 
)
Value:
ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, " Assertion Failed:\n{msg}" pattern, \
assertion_data.log(), ##__VA_ARGS__)
#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level,...)
Default printer for assertion messages.
Definition assert.h:35

◆ ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER

#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER (   cond,
  level,
  ... 
)
Value:
do { \
if (cond) { \
switch (zeroerr::assert_level::ZEROERR_CAT(level, _l)) { \
std::cerr << zeroerr::FgYellow << "WARN" << zeroerr::Reset; \
break; \
std::cerr << zeroerr::FgRed << "ERROR" << zeroerr::Reset; \
break; \
std::cerr << zeroerr::FgMagenta << "FATAL" << zeroerr::Reset; \
break; \
} \
std::cerr << zeroerr::format(__VA_ARGS__) << std::endl; \
} \
} while (0)
const char * FgMagenta
Definition color.cpp:47
std::string format(const char *fmt, T... args)
Format a string with arguments.
Definition format.h:25
const char * FgRed
Definition color.cpp:43
const char * FgYellow
Definition color.cpp:45
const char * Reset
Definition color.cpp:34

Default printer for assertion messages.

This macro defines the default printer for assertion messages. It prints the assertion message in different colors based on the assertion level.

The macro can be overridden by defining ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER before including this header. (Or undefine it and implement your own printer.)

◆ ZEROERR_REQUIRE

#define ZEROERR_REQUIRE (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, no_throw, false, __VA_ARGS__))

◆ ZEROERR_REQUIRE_EQ

#define ZEROERR_REQUIRE_EQ (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, ==, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_GE

#define ZEROERR_REQUIRE_GE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_GT

#define ZEROERR_REQUIRE_GT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, >, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_LE

#define ZEROERR_REQUIRE_LE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_LT

#define ZEROERR_REQUIRE_LT (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, <, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_NE

#define ZEROERR_REQUIRE_NE (   lhs,
  rhs,
  ... 
)    ZEROERR_ASSERT_CMP(lhs, !=, rhs, ZEROERR_ERROR, no_throw, false, __VA_ARGS__)

◆ ZEROERR_REQUIRE_NOT

#define ZEROERR_REQUIRE_NOT (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, no_throw, true, __VA_ARGS__))

◆ ZEROERR_REQUIRE_THROWS

#define ZEROERR_REQUIRE_THROWS (   cond,
  ... 
)    ZEROERR_EXPAND(ZEROERR_ASSERT_EXP(cond, ZEROERR_ERROR, throws, false, __VA_ARGS__))