return move-assignment dequeue optimization
This commit is contained in:
@@ -2554,7 +2554,7 @@ private:
|
||||
template<typename T1 = T, typename std::enable_if<
|
||||
!std::is_trivially_copyable<T1>::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<typename T1 = T, typename std::enable_if<
|
||||
std::is_trivially_copyable<T1>::value
|
||||
, int>::type = 0>
|
||||
|
||||
35
main.cpp
35
main.cpp
@@ -2,28 +2,41 @@
|
||||
#include "piiostream.h"
|
||||
#include "pibytearray.h"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
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<A> 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<A> v;
|
||||
v.push_back(A(1));
|
||||
// v.push_back(A(2));
|
||||
v.push_back(A(2));
|
||||
v.push_back(A(3));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user