class for tracing copy/move operations
#ifndef PLAYGROUND_MYDATA_H #define PLAYGROUND_MYDATA_H #include <ostream> #include <iostream> template<typename T> class MyData { public: MyData(T value) noexcept : value(value) { std::cout << __PRETTY_FUNCTION__ << std::endl; } operator T() noexcept { return value; } ~MyData() noexcept { std::cout << __PRETTY_FUNCTION__ << std::endl; } MyData(MyData&& other) noexcept : value(other.value) { std::cout << __PRETTY_FUNCTION__ << std::endl; } MyData(const MyData& other) noexcept : value(other.value) { std::cout << __PRETTY_FUNCTION__ << std::endl; } MyData& operator=(MyData&& other) noexcept { if (this == &other) { return *this; } std::cout << __PRETTY_FUNCTION__ << std::endl; this->~MyData(); new(this) MyData(std::move(other)); return *this; } MyData& operator=(const MyData& other) noexcept { if (this == &other) { return *this; } std::cout << __PRETTY_FUNCTION__ << std::endl; this->~MyData(); new(this) MyData(other); return *this; } friend std::ostream& operator<<(std::ostream& os, const MyData& data) { os << data.value; return os; } MyData& operator++() { ++value; return *this; } private: T value; }; #endif //PLAYGROUND_MYDATA_H