This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cpp:mydata.h [2018/09/01 13:15] – ↷ Page name changed from cpp:mydata to cpp:mydata.h allspark | cpp:mydata.h [2021/01/29 11:11] (current) – allspark | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # MyData | ||
| + | class for tracing copy/move operations | ||
| + | |||
| + | |||
| + | ```cpp | ||
| + | #include < | ||
| + | |||
| + | template< | ||
| + | class MyData | ||
| + | { | ||
| + | public: | ||
| + | MyData(T value) noexcept : value(value) | ||
| + | { | ||
| + | fmt:: | ||
| + | } | ||
| + | |||
| + | operator T() noexcept | ||
| + | { | ||
| + | return value; | ||
| + | } | ||
| + | |||
| + | ~MyData() noexcept | ||
| + | { | ||
| + | fmt:: | ||
| + | } | ||
| + | |||
| + | MyData(MyData&& | ||
| + | { | ||
| + | fmt:: | ||
| + | } | ||
| + | |||
| + | MyData(const MyData& other) noexcept : value(other.value) | ||
| + | { | ||
| + | fmt:: | ||
| + | } | ||
| + | |||
| + | MyData& operator=(MyData&& | ||
| + | { | ||
| + | if (this == &other) | ||
| + | { | ||
| + | return *this; | ||
| + | } | ||
| + | fmt:: | ||
| + | |||
| + | value = std:: | ||
| + | |||
| + | return *this; | ||
| + | } | ||
| + | |||
| + | MyData& operator=(const MyData& other) noexcept | ||
| + | { | ||
| + | if (this == &other) | ||
| + | { | ||
| + | return *this; | ||
| + | } | ||
| + | fmt:: | ||
| + | |||
| + | value = other.value; | ||
| + | |||
| + | return *this; | ||
| + | } | ||
| + | |||
| + | private: | ||
| + | T value; | ||
| + | }; | ||
| + | ``` | ||