#include #include "meowpp/Self.h" #include #include #include #include #include using namespace meow; class A { private: struct Myself{ int n; Myself() { } Myself(Myself const& m): n(m.n) { } ~Myself() { } }; Self const self; public: A(): self(){ self()->n = 0; } A(A const& b): self(b.self, Self::COPY_FROM) { } ~A() { } int num() const { return self->n; } int num(int k) { return (self()->n = k); } void copyFrom(A const& v) { self().copyFrom(v.self); } void referenceFrom(A const& v) { self().referenceFrom(v.self); } }; struct B { int n; int count; B() { n = 0; count = 1; } }; static const size_t N = 50; static A as[N]; static B *bs[N]; int main(){ srand(time(0)); for (size_t i = 0; i < N; i++) { bs[i] = new B; } for (size_t i = 0; i < 500; i++) { int k = rand(); if (k % 3 == 0) { // copyFrom int x, y; do { x = rand() % N; y = rand() % N; } while(x == y); as[x].copyFrom(as[y]); bs[x]->n = bs[y]->n; } else if (k % 3 == 1) { // referenceFrom int x, y; do { x = rand() % N; y = rand() % N; } while(x == y || x / (N / 5) != y / (N / 5)); as[x].referenceFrom(as[y]); bs[x]->count--; if (bs[x]->count == 0) { delete bs[x]; } bs[x] = bs[y]; bs[x]->count++; } else { // set value int x = rand() % N, v = rand() % 100; as[x].num(v); bs[x]->n = v; } bool chk = true; for (size_t n = 0; n < N; n++) { if (as[n].num() != bs[n]->n) { chk = false; break; } } if (!chk) { printf("false!\n"); return 1; } //for (size_t j = 0; j < N; j++) { printf("%d ", as[j].num()); } printf("\n"); } for (size_t i = 0; i < N; i++) { printf("%d ", as[i].num()); } printf("\n"); for (size_t i = 0; i < N; i++) { printf("%d ", bs[i]->n); } printf("\n"); printf("true\n"); return 0; }