#include #include #include "write-copy.h" #ifdef _TEST_ struct card { int id; card(int _id):id(_id){} }; struct card_list:single_base> { void accept(visitor>&v) { for(std::pair> me:m_map) { v.visit(me.second); //printf("====\n"); } } }; struct visit_log:visitor> { bool visit(std::shared_ptr c) { //printf("vist :::::::%d\n",c->id); return true; } }; template<> std::shared_ptr single_base>::m_instance=std::make_shared(); void run() { visit_log vl; card_list::instance()->accept(vl); } int main() { std::vector> v; //std::thread th(run); for(int i=0;i<10000;i++) { card_list::instance()->add(i,std::make_shared(i));//每次生成一个对象 printf("%d %p\n",i,card_list::instance().get()); v.push_back(card_list::instance()); } for(int i=0;i<100;i++) { // printf("%d %p\n",i,v[i].get()); } //th.join(); visit_log vl; card_list::instance()->accept(vl); // printf("%p",card_list::instance()->get(5)); auto x = card_list::instance()->get(100); if(x!=nullptr) printf("...........id:%d\n",x->id); else printf("nullptr...\n"); return 0; } #endif