提交 75a7f57c 编写于 作者: 邹晓航

No commit message

No commit message
上级 3b2d0955
......@@ -47,6 +47,7 @@ TinySTL
* unordered_set:100%
* unique_ptr:100%
* shared_ptr:100%
* cow_ptr:100%
* STL Algorithms:
* fill:100%
* fill_n:100%
......@@ -563,6 +564,23 @@ TinySTL
up.reset(new string("hello"));
assert(*up == "hello");
####(19):cow_ptr
cow_ptr<string> cp1(new string("zouxiaohang"));
auto cp2 = cp1, cp3 = cp1;
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");
*cp2;//read
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");
cp2->append(" C++");//write
assert(*cp1 == *cp3 && *cp3 == "zouxiaohang");
assert(*cp2 == "zouxiaohang C++");
......@@ -20,12 +20,31 @@ namespace TinySTL{
assert(cp1 == cp2 && !(cp2 != cp3));
*cp1 = "zouxiaohang";
assert(*cp1 == "zouxiaohang");
assert(*cp2 == "hello" && *cp3 == "hello");
cow_ptr<string> cp4;
assert(cp4 == nullptr);
}
void testCase2(){
cow_ptr<string> cp1(new string("zouxiaohang"));
auto cp2 = cp1, cp3 = cp1;
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");
*cp2;//read
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");
cp2->append(" C++");//write
assert(*cp1 == *cp3 && *cp3 == "zouxiaohang");
assert(*cp2 == "zouxiaohang C++");
}
void testAllCases(){
testCase1();
testCase2();
}
}
}
\ No newline at end of file
......@@ -26,6 +26,8 @@
#include "Test\VectorTest.h"
using namespace TinySTL::Profiler;
#include <string>
#include <type_traits>
int main(){
TinySTL::AlgorithmTest::testAllCases();
......@@ -50,6 +52,10 @@ int main(){
TinySTL::Unordered_setTest::testAllCases();
TinySTL::VectorTest::testAllCases();
std::string s;
if (std::is_const<decltype(s.cbegin())>::value){
std::cout << "const" << std::endl;
}
system("pause");
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册