Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iomanip>
- #include <iostream>
- #include <string>
- using namespace std;
- template <typename T>
- void AssertImpl(const T& t, const string& expr, const string& file_name, const string& func_name,int line, const string& hint = "")
- {
- if (t == false)
- {
- if (!hint.empty())
- {
- cout << file_name << "(" << line << ")" << ": " << func_name << ": " << "ASSERT(" << expr << ")" << " failed. Hint: " << hint << endl;
- abort();
- }
- else
- {
- cout << file_name << "(" << line << ")" << ": " << func_name << ": " << "ASSERT(" << expr << ")" << " failed." << endl;
- abort();
- }
- }
- }
- #define ASSERT(expr) AssertImpl( (expr), (#expr), __FILE__, __FUNCTION__, __LINE__ )
- #define ASSERT_HINT(expr, hint) AssertImpl( (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
Advertisement