HyperHDG
Macros
hy_assert.hxx File Reference

This file provides the function hy_assert. More...

#include <iostream>
#include <sstream>
Include dependency graph for hy_assert.hxx:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define hy_assert(Expr, Msg)
 The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag. More...
 

Detailed Description

This file provides the function hy_assert.


This is a wrapper file to provide a function that allows to use assertions that are similar to those provided by cassert. That is, we define a macro hy_assert that implements assert. If a user wants to use assertions, it is recommended to use hy_assert(Expr, Msg). The use of the function __Hy_Assert is not recommended.

Function hy_assert takes two arguments. The first argument is evaluated to a boolean and if this returns true, nothing is done. If the argument is false, the running program is terminated and the second argument is displayed as part of an error message. Here, the second argument is handled as a stringstream (without initial <<). Thus, for two integers a and b, a function call might look like: hy_assert( a == b , "Integers have not been the same, since a turned out to be " << a << " and b was " << b << "." );

Whether this functionality is active or not can be deduced via setting NDEBUG, when the code is compiled. Using this functionality makes your program significantly slower. However, usage is highly recommended for testing.

Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.

Macro Definition Documentation

◆ hy_assert

#define hy_assert (   Expr,
  Msg 
)
Value:
{ \
std::stringstream __hy_assertion_text; \
__hy_assertion_text << Msg; \
__Hy_Assert(#Expr, Expr, __FILE__, __LINE__, __hy_assertion_text); \
} \
static_assert(true, "")

The assertion to be used within HyperHDG — deactivate using -DNDEBUG compile flag.


Parameters
ExprC++ Expression that can be evaluated to true or false.
MsgMessage that is to be displayed if Expr is evaluated to false.