-
- Downloads
There was a problem fetching the pipeline summary.
Merge branch 'feature/assert-and-return' into 'master'
Add macro DUNE_ASSERT_AND_RETURN This is an alternative to !128. 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: ```c++ 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: * In a non-`constexpr` context an `assert()` will fail if the condition is not matched. The error message will be slightly different from a classic assertion. * In a `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`. See merge request !142
No related branches found
No related tags found
Pipeline #
Showing
- dune/common/CMakeLists.txt 1 addition, 0 deletionsdune/common/CMakeLists.txt
- dune/common/assertandreturn.hh 20 additions, 0 deletionsdune/common/assertandreturn.hh
- dune/common/hybridutilities.hh 3 additions, 3 deletionsdune/common/hybridutilities.hh
- dune/common/test/CMakeLists.txt 12 additions, 0 deletionsdune/common/test/CMakeLists.txt
- dune/common/test/assertandreturntest.cc 85 additions, 0 deletionsdune/common/test/assertandreturntest.cc
dune/common/assertandreturn.hh
0 → 100644
dune/common/test/assertandreturntest.cc
0 → 100644
Please register or sign in to comment