Advertisement
Ilya_konstantinov

main.cpp

Sep 16th, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | Source Code | 0 0
  1. /*
  2. Компилирую командой
  3. g++ harakiri.cpp main.cpp -fsanitize=address -o main
  4. и запускаю
  5. ./main
  6. */
  7.  
  8. #include <cassert>
  9. #include "harakiri.h"
  10.  
  11. #include <string>
  12. #include <type_traits>
  13. #include <utility>
  14.  
  15. class DoConstWork {
  16. public:
  17.     std::string Do(const OneTimeCallback* callback) {
  18.         // Pretend to do some work.
  19.         return std::move(*callback)();
  20.         // Try this and make sure it fails.
  21.         // return std::move(*callback)() + std::move(*callback)();
  22.         // return (*callback)();
  23.     }
  24. };
  25.  
  26. class DoWork {
  27. public:
  28.     std::string Do(OneTimeCallback* callback) {
  29.         // Pretend to do some work.
  30.         return std::move(*callback)();
  31.         // Try this and make sure it fails.
  32.         // return std::move(*callback)() + std::move(*callback)();
  33.         // return (*callback)();
  34.     }
  35. };
  36.  
  37.  
  38. #define REQUIRE assert
  39. int main() {
  40.     AwesomeCallback* c = new AwesomeCallback(std::string("C++ shine extreme "));
  41.     DoWork d;
  42.     REQUIRE(d.Do(c) == "C++ shine extreme awesomeness");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement