Skip to content

Instantly share code, notes, and snippets.

@basp1
Created February 28, 2017 09:12
Show Gist options
  • Save basp1/6a385287866c23eeece429f9f27054f4 to your computer and use it in GitHub Desktop.
Save basp1/6a385287866c23eeece429f9f27054f4 to your computer and use it in GitHub Desktop.
ensure macro
#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