Add macro DUNE_ASSERT_AND_RETURN
1 unresolved thread
1 unresolved thread
Compare changes
Files
5+ 12
− 0
@@ -2,6 +2,18 @@ dune_add_test(SOURCES arraylisttest.cc)
This is an alternative to !128 (closed).
In C++11 and with not fully C++14 compliant compilers constexpr
functions
can only have a return statement. This prevents the use of assert()
inside
of constexpr
functions. This macro can be used as a workaround like this:
constexpr auto foo(int a, int b, x)
{
return DUNE_ASSERT_AND_RETURN(a<b, x);
}
For NDEBUG
there is no penalty. Otherwise there are two options:
constexpr
context an assert()
will fail if the condition
is not matched. The error message will be slightly different from a
classic assertion.constexpr
context the assert()
branch will be ignored if the
is condition is matched. Otherwise this will lead to a compile error
(like static_assert
) because the branch using assert()
is not constexpr
.