Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Компилирую командой
- g++ harakiri.cpp main.cpp -fsanitize=address -o main
- и запускаю
- ./main
- */
- #include <cassert>
- #include "harakiri.h"
- #include <string>
- #include <type_traits>
- #include <utility>
- class DoConstWork {
- public:
- std::string Do(const OneTimeCallback* callback) {
- // Pretend to do some work.
- return std::move(*callback)();
- // Try this and make sure it fails.
- // return std::move(*callback)() + std::move(*callback)();
- // return (*callback)();
- }
- };
- class DoWork {
- public:
- std::string Do(OneTimeCallback* callback) {
- // Pretend to do some work.
- return std::move(*callback)();
- // Try this and make sure it fails.
- // return std::move(*callback)() + std::move(*callback)();
- // return (*callback)();
- }
- };
- #define REQUIRE assert
- int main() {
- AwesomeCallback* c = new AwesomeCallback(std::string("C++ shine extreme "));
- DoWork d;
- REQUIRE(d.Do(c) == "C++ shine extreme awesomeness");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement