diff --git a/README.md b/README.md index b85ecd4fdb932d38b0c4f4e25b192680ef4268fb..3fc63fbf717b8816d4d1037b78919462e2681625 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ TinySTL * list:100% * unordered_set:100% * unique_ptr:100% + * shared_ptr:100% * STL Algorithms: * fill:100% * fill_n:100% @@ -103,6 +104,7 @@ TinySTL * directed_graph:100% * trie tree:100% * unique_ptr:100% + * shared_ptr:100% #TinySTL性能测试: ###测试环境:Windows 7 && VS2013 && release模式 @@ -530,4 +532,52 @@ TinySTL } std::cout << std::endl; -![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/trie_tree.png) \ No newline at end of file +![image](https://raw.githubusercontent.com/zouxiaohang/TinySTL/master/TinySTL/ScreenShots/trie_tree.png) + + + +####(17):shared_ptr + + shared_ptr sp1(new int(10)); + assert(*(sp1.get()) == 10); + + shared_ptr sp2(new int(1), default_delete()); + assert(sp2.use_count() == 1); + + auto sp3(sp2); + assert(sp3.use_count() == 2); + + auto sp4 = sp2; + assert(sp4.use_count() == 3); + + assert(sp2.get() == sp3.get() && sp2.get() == sp4.get()); + assert(sp2 == sp3 && !(sp2 != sp4)); + + shared_ptr sp5(new string("hello")); + assert(*sp5 == "hello"); + sp5->append(" world"); + assert(*sp5 == "hello world"); + + auto sp6 = make_shared(10, '0'); + assert(*sp6 == "0000000000"); + + shared_ptr spp; + assert(spp == nullptr); + assert(!(spp != nullptr)); + + + +####(18):unique_ptr + + auto up = make_unique(10, '0'); + up->append("111"); + assert(*up == "0000000000111"); + + up.release(); + assert(up == nullptr); + + up.reset(new string("hello")); + assert(*up == "hello"); + + +