diff --git a/libs/main/containers/pideque.h b/libs/main/containers/pideque.h index ee3741a9..17bd087d 100644 --- a/libs/main/containers/pideque.h +++ b/libs/main/containers/pideque.h @@ -2554,7 +2554,7 @@ private: template::value , int>::type = 0> - inline void elementNew(T * to, T && from) {new(to)T(from);} + inline void elementNew(T * to, T && from) {new(to)T(std::move(from));} template::value , int>::type = 0> diff --git a/main.cpp b/main.cpp index 5400a29b..5432cbf4 100644 --- a/main.cpp +++ b/main.cpp @@ -2,28 +2,41 @@ #include "piiostream.h" #include "pibytearray.h" #include +#include using namespace PICoutManipulators; +#define SZ 256 class A { public: + A() : id_(666) { + arr = new int[SZ]; + piCout << "def A()" << id_ << this << arr; + } A(int id) : id_(id) { - piCout << "A()" << id_ << this; + arr = new int[SZ]; + piCout << "A(int)" << id_ << this << arr; } A(const A & a) { + arr = new int[SZ]; id_ = a.id_; - piCout << "A(A)" << id_ << this; + piCout << "A(A)" << id_ << this << arr; } A(A && a) { std::swap(id_, a.id_); - piCout << "move A(A)" << id_ << this; + std::swap(arr, a.arr); + piCout << "move A(A)" << id_ << this << arr; } ~A() { - piCout << "~A()" << id_ << this; + if (arr) { + memset(arr, 0, SZ * 4); + delete arr; + } + piCout << "~A()" << id_ << this << arr; //id_ = 0; } @@ -35,11 +48,13 @@ public: inline A & operator =(A && a) { std::swap(id_, a.id_); + std::swap(arr, a.arr); piCout << "move A=" << id_ << this; return *this; } private: - int id_; + int id_ = -1; + int * arr = 0; }; @@ -62,15 +77,21 @@ int main(int argc, char * argv[]) { piCout << "pip 3.1"; { PIDeque v; + //A a; + //v.push_back(a); + //v.push_back(std::move(a)); v.push_back(A(1)); -// v.push_back(A(2)); + v.push_back(A(2)); + v.push_back(A(3)); } + piCout << ""; piCout << "std"; { std::vector v; v.push_back(A(1)); -// v.push_back(A(2)); + v.push_back(A(2)); + v.push_back(A(3)); } return 0; }