Created
June 1, 2017 19:24
-
-
Save socantre/c8e69c4c7232d822b2711f13b46e969b to your computer and use it in GitHub Desktop.
require() with REQUIRE() macro to deal with source locations, until we get a real std::source_location type
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 <stdexcept> | |
struct require_error : std::runtime_error { | |
using std::runtime_error::runtime_error; | |
}; | |
void require(bool b, char const *message) { | |
if (!b) { | |
throw require_error(message); | |
} | |
} | |
#define STRINGIZE2(x) STRINGIZE(x) | |
#define STRINGIZE(x) #x | |
#define SOURCE_LOCATION __FILE__ ":" STRINGIZE2(__LINE__) | |
#define REQUIRE(condition, reason) (require((condition), SOURCE_LOCATION ": " reason)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment