dimanche 17 avril 2022

constexpr Functions that throw (runtime) errors

I'm trying to write a function that I would like to be used in both constexpr situations as well as runtime situations. The function does several debug-only checks, and these calls are causing the function to fail to compile with constexpr.

I can write the function to use static asserts, but then this will fail to compile with runtime calls.

Is there a clever way to write a verification/test macro or function that can either call a runtime error, or a static assert, depending on which situation it is being compiled in? Or is it necessary to write two versions of functions that we want to be compatible with constexpr (when they test for runtime errors)?

Aucun commentaire:

Enregistrer un commentaire