This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| cpp:mydata.h [2018/09/01 13:15] – allspark | cpp:mydata.h [2021/01/29 11:11] (current) – allspark | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ```cpp | ```cpp | ||
| - | #ifndef PLAYGROUND_MYDATA_H | + | #include <fmt/ |
| - | #define PLAYGROUND_MYDATA_H | + | |
| - | + | ||
| - | #include <ostream> | + | |
| - | #include < | + | |
| template< | template< | ||
| Line 17: | Line 13: | ||
| MyData(T value) noexcept : value(value) | MyData(T value) noexcept : value(value) | ||
| { | { | ||
| - | | + | |
| } | } | ||
| + | |||
| operator T() noexcept | operator T() noexcept | ||
| { | { | ||
| return value; | return value; | ||
| } | } | ||
| + | |||
| ~MyData() noexcept | ~MyData() noexcept | ||
| { | { | ||
| - | | + | |
| } | } | ||
| + | |||
| MyData(MyData&& | MyData(MyData&& | ||
| { | { | ||
| - | | + | |
| } | } | ||
| + | |||
| MyData(const MyData& other) noexcept : value(other.value) | MyData(const MyData& other) noexcept : value(other.value) | ||
| { | { | ||
| - | | + | |
| } | } | ||
| + | |||
| MyData& operator=(MyData&& | MyData& operator=(MyData&& | ||
| { | { | ||
| Line 46: | Line 42: | ||
| return *this; | return *this; | ||
| } | } | ||
| - | | + | |
| - | + | ||
| - | | + | |
| - | new(this) MyData(std:: | + | |
| return *this; | return *this; | ||
| } | } | ||
| + | |||
| MyData& operator=(const MyData& other) noexcept | MyData& operator=(const MyData& other) noexcept | ||
| { | { | ||
| Line 60: | Line 55: | ||
| return *this; | return *this; | ||
| } | } | ||
| - | | + | |
| - | + | ||
| - | | + | |
| - | new(this) MyData(other); | + | |
| return *this; | return *this; | ||
| - | } | + | } |
| - | + | ||
| - | friend std:: | + | |
| - | { | + | |
| - | os << data.value; | + | |
| - | return os; | + | |
| - | } | + | |
| - | + | ||
| - | MyData& operator++() | + | |
| - | { | + | |
| - | ++value; | + | |
| - | return *this; | + | |
| - | } | + | |
| - | + | ||
| private: | private: | ||
| T value; | T value; | ||
| }; | }; | ||
| - | |||
| - | #endif // | ||
| ``` | ``` | ||