This commit is contained in:
邹晓航
2015-03-19 16:09:28 +08:00
parent 16fe2265b8
commit 39b6e637be
3 changed files with 7 additions and 2 deletions

View File

@@ -569,7 +569,7 @@ TinySTL
####(19):cow_ptr
cow_ptr<string> cp1(new string("zouxiaohang"));
cow_ptr<string> cp1 = make_cow<string>("zouxiaohang");
auto cp2 = cp1, cp3 = cp1;
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");

View File

@@ -68,6 +68,11 @@ namespace TinySTL{
template<class _T>
friend class Detail::proxy;
};
template<class T, class... Args>
cow_ptr<T> make_cow(Args...args){
return cow_ptr<T>(new T(std::forward<Args>(args)...));
}
}
#include "Detail\COWPtr.impl.h"

View File

@@ -28,7 +28,7 @@ namespace TinySTL{
assert(cp4 == nullptr);
}
void testCase2(){
cow_ptr<string> cp1(new string("zouxiaohang"));
cow_ptr<string> cp1 = make_cow<string>("zouxiaohang");
auto cp2 = cp1, cp3 = cp1;
assert(cp1 == cp2 && cp2 == cp3);
assert(*cp1 == *cp2 && *cp2 == *cp3 && *cp3 == "zouxiaohang");