98 lines
1.6 KiB
C++
98 lines
1.6 KiB
C++
#include "pip.h"
|
|
#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) {
|
|
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 << arr;
|
|
}
|
|
|
|
A(A && a) {
|
|
std::swap(id_, a.id_);
|
|
std::swap(arr, a.arr);
|
|
piCout << "move A(A)" << id_ << this << arr;
|
|
}
|
|
|
|
~A() {
|
|
if (arr) {
|
|
memset(arr, 0, SZ * 4);
|
|
delete arr;
|
|
}
|
|
piCout << "~A()" << id_ << this << arr;
|
|
//id_ = 0;
|
|
}
|
|
|
|
inline A & operator =(const A & a) {
|
|
id_ = a.id_;
|
|
piCout << "A =" << id_ << this;
|
|
return *this;
|
|
}
|
|
|
|
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_ = -1;
|
|
int * arr = 0;
|
|
};
|
|
|
|
|
|
//class B {
|
|
//public:
|
|
// B() {a_ = nullptr;}
|
|
// ~B() {if (a_) delete a_;}
|
|
|
|
// void setA(A && a) {
|
|
// a_ = (A *)malloc(sizeof(a));
|
|
// memcpy(a_, &a, sizeof(a));
|
|
// operator delete(&a);
|
|
// }
|
|
// void setA(const A & a) {a_ = new A(a);}
|
|
//private:
|
|
// A * a_;
|
|
//};
|
|
|
|
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(3));
|
|
}
|
|
|
|
piCout << "";
|
|
piCout << "std";
|
|
{
|
|
std::vector<A> v;
|
|
v.push_back(A(1));
|
|
v.push_back(A(2));
|
|
v.push_back(A(3));
|
|
}
|
|
return 0;
|
|
}
|