This commit is contained in:
18
README.md
18
README.md
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user