Advertisement
kutuzzzov

урок 3

Aug 26th, 2022
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. void AssertImpl(bool value, const string& expr, const string& file,
  9.                      const string& func, unsigned line, const string& hint) {
  10.     if (value != true) {
  11.         cout << boolalpha;
  12.         cout << file << "("s << line << "): "s << func << ": "s;
  13.         cout << "ASSERT("s << expr << ") failed."s;
  14.         if (!hint.empty()) {
  15.             cout << " Hint: "s << hint;
  16.         }
  17.         cout << endl;
  18.         abort();
  19.     }
  20. }
  21.  
  22. #define ASSERT(expr) AssertImpl((expr), #expr, __FILE__, __FUNCTION__, __LINE__, ""s)
  23.  
  24. #define ASSERT_HINT(expr, hint) AssertImpl((expr), #expr, __FILE__, __FUNCTION__, __LINE__, (hint))
  25.  
  26. int main() {
  27.     string hello = "hello"s;
  28.     ASSERT(!hello.empty());
  29.     ASSERT_HINT(2 + 2 == 5, "This will fail"s);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement