1 #include "../gintenlib/move_ptr.hpp"
5 // コメントも少なく非常に見難いテストですが、
6 // 出力とソースを見比べて何が起こってるかを把握してみてください
10 // virtual implementation model
13 virtual void foo() = 0;
16 static gintenlib::move_ptr<hoge> create( int i );
17 // static std::auto_ptr<hoge> create( int i );
27 my_deleter( int x = 0 ) : i(x) {}
30 void operator()( T* ptr )
32 cout << *this << ": deleting '" << *ptr << "'...\n";
36 friend ostream& operator<< ( ostream& os, const my_deleter& rhs )
42 os << " No." << rhs.i;
53 gintenlib::move_ptr<hoge> p1, p2( hoge::create(2) );
61 assert( !( p1 == p2 ) );
63 gintenlib::move_ptr<hoge> p3 = p2;
77 gintenlib::move_ptr< int, my_deleter > p4( new int(4) ), p5( new int(5), my_deleter(2) );
81 gintenlib::move_ptr< const int, my_deleter > p6( p4 );
82 p4.reset( new int(4), my_deleter(3) );
85 cout << get_deleter(p4) << endl;
86 delete p4.release( del );
89 p4 = gintenlib::const_pointer_cast<int>(p6);
92 cout << "scope out.\n";
95 // 本来は別ファイルに置くべきですが簡略のため。
96 gintenlib::move_ptr<hoge> hoge::create( int i )
100 explicit impl( int x = 0 ) : i(x)
102 cout << "hoge(" << i << ") is constructed.\n";
106 cout << "hoge(" << i << ") is destructed.\n";
111 cout << "hoge(" << i << ").foo() is called.\n";
118 return gintenlib::move_ptr<hoge>( new impl(i) );