This commit is contained in:
邹晓航
2015-03-16 19:14:01 +08:00
parent 3b2d095555
commit 75a7f57ca1
3 changed files with 43 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ TinySTL
* unordered_set100%
* unique_ptr100%
* shared_ptr100%
* cow_ptr100%
* STL Algorithms:
* fill100%
* fill_n100%
@@ -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++");

View File

@@ -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();
}
}
}

View 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;
}