Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iomanip>
- #include <iostream>
- #include <string>
- using namespace std;
- void Assert(bool value, const string& string_value, const string& file_name, const string& func_name, unsigned line_number, const string& hint) {
- if (!value) {
- cout << file_name << "("s << line_number << "): "s << func_name << ": "s;
- cout << "ASSERT("s << string_value << ") failed."s;
- if (!hint.empty()) {
- cout << " Hint: "s << hint;
- }
- cout << endl;
- abort();
- }
- }
- #define ASSERT(expr) Assert(expr, #expr, __FILE__, __FUNCTION__, __LINE__, ""s)
- #define ASSERT_HINT(expr, hint) Assert(expr, #expr, __FILE__, __FUNCTION__, __LINE__, (hint))
- int main() {
- string hello = "hello"s;
- ASSERT(!hello.empty());
- ASSERT_HINT(2 + 2 == 5, "This will fail"s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment