I have been reading about using constexpr instead of using macros for better safety, as macros can lead to undefined behavior. However, if I have the code in the following example, is it okay to do this, and just use preprocessor if statements (#if), or should I change the macros to constexpr bool.
Here is what I wanted to do:
#if NDEBUG
#define ENABLE_VALIDATION_LAYERS 0
#else
#define ENABLE_VALIDATION_LAYERS 1
#endif
vs
#if NDEBUG
constexpr bool enable_validation_layers = false;
#else
constexpr bool enable_validation_layers = true;
#endif
Code usage right now looks like this:
//if validation layers are not enabled, the validation support does not need to be checked
#if ENABLE_VALIDATION_LAYERS
if (!CheckValidationLayerSupport()) //function that returns a bool to check if validation layers are supported
{
throw std::runtime_error("validation layers requested, but not available!");
}
#endif