Advertisement
Guest User

gotw_102_rvo_test

a guest
Jan 22nd, 2012
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <memory>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. struct A
  9. {
  10.     int m;
  11.     A(int i) : m(i) { printf("ctor(%d)\n", i); }
  12.     A(A const& o) : m(o.m) { printf("cctor(%d)\n", o.m); }
  13.     A const& operator=(A const& o){ m = o.m; printf("op=(%d)\n", o.m); }
  14.     ~A() { printf("dtor\n"); }
  15. };
  16.  
  17. A foo() { return A( rand() ); }
  18. auto_ptr<A> make_unique(A&& a) { return auto_ptr<A>(new A(forward<A>(a))); }
  19. //unique_ptr<A> make_unique(A&& a) { return unique_ptr<A>(new A(forward<A>(a))); }
  20.  
  21. int main()
  22. {
  23.     srand(time(NULL));
  24.     auto_ptr<A> p( new A(foo()) );
  25. //    auto_ptr<A> p( make_unique(foo()) );
  26. //    unique_ptr<A> p( make_unique(foo()) );
  27.     return 1;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement