MyData

class for tracing copy/move operations

snippet.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;
};