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
cpp:mydata.h [2018/09/01 13:15] allsparkcpp:mydata.h [2021/01/29 11:11] (current) allspark
Line 5: Line 5:
  
 ```cpp ```cpp
-#ifndef PLAYGROUND_MYDATA_H +#include <fmt/format.h>
-#define PLAYGROUND_MYDATA_H +
- +
-#include <ostream> +
-#include <iostream>+
  
 template<typename T> template<typename T>
Line 17: Line 13:
     MyData(T value) noexcept : value(value)     MyData(T value) noexcept : value(value)
     {     {
-      std::cout << __PRETTY_FUNCTION__ << std::endl;+      fmt::print("{}\n", __PRETTY_FUNCTION__);
     }     }
 + 
     operator T() noexcept     operator T() noexcept
     {     {
       return value;       return value;
     }     }
 + 
     ~MyData() noexcept     ~MyData() noexcept
     {     {
-      std::cout << __PRETTY_FUNCTION__ << std::endl;+      fmt::print("{}\n", __PRETTY_FUNCTION__);
     }     }
 + 
     MyData(MyData&& other) noexcept : value(other.value)     MyData(MyData&& other) noexcept : value(other.value)
     {     {
-      std::cout << __PRETTY_FUNCTION__ << std::endl;+      fmt::print("{}\n", __PRETTY_FUNCTION__);
     }     }
 + 
     MyData(const MyData& other) noexcept : value(other.value)     MyData(const MyData& other) noexcept : value(other.value)
     {     {
-      std::cout << __PRETTY_FUNCTION__ << std::endl;+      fmt::print("{}\n", __PRETTY_FUNCTION__);
     }     }
 + 
     MyData& operator=(MyData&& other) noexcept     MyData& operator=(MyData&& other) noexcept
     {     {
Line 46: Line 42:
         return *this;         return *this;
       }       }
-      std::cout << __PRETTY_FUNCTION__ << std::endl+      fmt::print("{}\n", __PRETTY_FUNCTION__)
- +  
-      this->~MyData(); +      value = std::move(other).value
-      new(this) MyData(std::move(other))+ 
       return *this;       return *this;
     }     }
 + 
     MyData& operator=(const MyData& other) noexcept     MyData& operator=(const MyData& other) noexcept
     {     {
Line 60: Line 55:
         return *this;         return *this;
       }       }
-      std::cout << __PRETTY_FUNCTION__ << std::endl+      fmt::print("{}\n", __PRETTY_FUNCTION__)
- +  
-      this->~MyData(); +      value = other.value
-      new(this) MyData(other)+ 
       return *this;       return *this;
-    } +    }  
- + 
-    friend std::ostream& operator<<(std::ostream& os, const MyData& data) +
-    { +
-      os << data.value; +
-      return os; +
-    } +
- +
-    MyData& operator++() +
-    { +
-      ++value; +
-      return *this; +
-    } +
- +
   private:   private:
     T value;     T value;
 }; };
- 
-#endif //PLAYGROUND_MYDATA_H 
 ``` ```
cpp/mydata.h.1535800536.txt.gz · Last modified: by allspark