添加swap

This commit is contained in:
邹晓航
2014-10-12 14:54:02 +08:00
parent ab840b2a33
commit 1c00451748
5 changed files with 22 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#define _QUEUE_H_
#include "Deque.h"
#include "Functional.h"
#include "Vector.h"
namespace TinySTL{

View File

@@ -4,6 +4,7 @@
#include "Allocator.h"
#include "ReverseIterator.h"
#include "UninitializedFunctions.h"
#include "Utility.h"
#include <cstring>
#include <type_traits>
@@ -122,9 +123,9 @@ namespace TinySTL{
string& replace(iterator i1, iterator i2, InputIterator first, InputIterator last);
void swap(string& str){
std::swap(start_, str.start_);
std::swap(finish_, str.finish_);
std::swap(endOfStorage_, str.endOfStorage_);
TinySTL::swap(start_, str.start_);
TinySTL::swap(finish_, str.finish_);
TinySTL::swap(endOfStorage_, str.endOfStorage_);
}
size_t copy(char* s, size_t len, size_t pos = 0) const{
auto ptr = TinySTL::uninitialized_copy(begin() + pos, begin() + pos + len, s);

View File

@@ -99,6 +99,7 @@
<ClInclude Include="String.h" />
<ClInclude Include="TypeTraits.h" />
<ClInclude Include="UninitializedFunctions.h" />
<ClInclude Include="Utility.h" />
<ClInclude Include="Vector.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -77,5 +77,8 @@
<ClInclude Include="Functional.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Utility.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>

13
TinySTL/Utility.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _UTILITY_H_
#define _UTILITY_H_
namespace TinySTL{
//************ [swap] ***************
template<class T>
void swap(T& a, T& b){
T temp = a;
a = b;
b = temp;
}
}
#endif