Skip to content

Make DUNE_THROW usable in constexpr context

Carsten Gräser requested to merge feature/constexpr-throw into master

Instead of using a do ... while loop, this extends the exception with operator<< such that one can directly pipe in values. The extension is done via the new class Dune::ExceptionStream<E> that derives from E and implements operator<<. This allows to use DUNE_THROW in constexpr contexts (unless the selected code path does not throw) which is now checked via a test.

As a by-product one can now also pipe values after DUNE_THROW e.g. using

DUNE_THROW(E, "foo" << 1) << 2 << 3;

If desired we could also support

DUNE_THROW(E) << 2 << 3;

directly.

Notice that DUNE_THROW exists for two main reasons: For (a) conveniently add the error location to the message and (b) providing the stream functionality. With this patch the second reason is void and no longer reguires a macro, because one can directly use:

throw Dune::ExceptionStream<E>() << 2 << 3;

Merge request reports

Loading