1 #include <memory> 2 #include <string> 3 4 struct Deleter { operator ()Deleter5 void operator()(void *) {} 6 7 int a; 8 int b; 9 }; 10 11 struct Foo { 12 int data; 13 std::unique_ptr<Foo> fp; 14 }; 15 main()16int main() { 17 std::unique_ptr<char> nup; 18 std::unique_ptr<int> iup(new int{123}); 19 std::unique_ptr<std::string> sup(new std::string("foobar")); 20 21 std::unique_ptr<char, Deleter> ndp; 22 std::unique_ptr<int, Deleter> idp(new int{456}, Deleter{1, 2}); 23 std::unique_ptr<std::string, Deleter> sdp(new std::string("baz"), 24 Deleter{3, 4}); 25 26 std::unique_ptr<Foo> fp(new Foo{3}); 27 28 // Set up a structure where we have a loop in the unique_ptr chain. 29 Foo* f1 = new Foo{1}; 30 Foo* f2 = new Foo{2}; 31 f1->fp.reset(f2); 32 f2->fp.reset(f1); 33 34 return 0; // Set break point at this line. 35 } 36