User Tools

Site Tools


cpp:mydata.h

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cpp:mydata.h [2018/09/01 13:15] – ↷ Page name changed from cpp:mydata to cpp:mydata.h allsparkcpp:mydata.h [2021/01/29 11:11] (current) allspark
Line 1: Line 1:
 +# MyData
  
 +class for tracing copy/move operations
 +
 +
 +```cpp
 +#include <fmt/format.h>
 +
 +template<typename T>
 +class MyData
 +{
 +  public:
 +    MyData(T value) noexcept : value(value)
 +    {
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 +    }
 + 
 +    operator T() noexcept
 +    {
 +      return value;
 +    }
 + 
 +    ~MyData() noexcept
 +    {
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 +    }
 + 
 +    MyData(MyData&& other) noexcept : value(other.value)
 +    {
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 +    }
 + 
 +    MyData(const MyData& other) noexcept : value(other.value)
 +    {
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 +    }
 + 
 +    MyData& operator=(MyData&& other) noexcept
 +    {
 +      if (this == &other)
 +      {
 +        return *this;
 +      }
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 + 
 +      value = std::move(other).value;
 + 
 +      return *this;
 +    }
 + 
 +    MyData& operator=(const MyData& other) noexcept
 +    {
 +      if (this == &other)
 +      {
 +        return *this;
 +      }
 +      fmt::print("{}\n", __PRETTY_FUNCTION__);
 + 
 +      value = other.value;
 + 
 +      return *this;
 +    } 
 + 
 +  private:
 +    T value;
 +};
 +```
cpp/mydata.h.1535800512.txt.gz · Last modified: by allspark