Created
February 28, 2017 09:12
-
-
Save basp1/6a385287866c23eeece429f9f27054f4 to your computer and use it in GitHub Desktop.
ensure macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <exception> | |
#define DEBUG_STRINGIFY(x) #x | |
#define DEBUG_TO_STRING(x) DEBUG_STRINGIFY(x) | |
#define DEBUG_LOCATION "file: " __FILE__ ". line: " DEBUG_TO_STRING(__LINE__) | |
#define THROW_EXCEPTION(MESSAGE) throw std::exception(MESSAGE) | |
#define NOT_IMPLEMENTED THROW_EXCEPTION("Not implemented yet"); | |
#ifdef DISABLE_ENSURANCES | |
#define ENSURE2(COND, MESSAGE) | |
#define ENSURE(COND) | |
#else | |
#define ENSURE2(COND, MESSAGE) \ | |
if (!(COND)) { \ | |
THROW_EXCEPTION(MESSAGE ". " DEBUG_LOCATION); \ | |
} | |
#define ENSURE(COND) ENSURE2(COND, "condition `" #COND "' fails") | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment