Created
April 15, 2017 09:14
-
-
Save hryniuk/8d0c824c9dd21b4fec9dd81b59668aad to your computer and use it in GitHub Desktop.
Ensure macro to check preconditions
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
#include <iostream> | |
#define ENSURE(x) do { \ | |
if (not (x)) {std::cerr << __FILE__ << " " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " " << #x << " assert failed!\n";} \ | |
} while(false) | |
void f(int x) | |
{ | |
ENSURE(x > 0); | |
} | |
int main() | |
{ | |
f(10); | |
f(-1); // print "ensure.cpp void f(int):9 x > 0 assert failed" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment