bug fix
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Profiler\Profiler.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Algorithm.h" />
|
||||
@@ -84,6 +85,7 @@
|
||||
<ClInclude Include="Allocator.h" />
|
||||
<ClInclude Include="Construct.h" />
|
||||
<ClInclude Include="Iterator.h" />
|
||||
<ClInclude Include="Profiler\Profiler.h" />
|
||||
<ClInclude Include="TypeTraits.h" />
|
||||
<ClInclude Include="UninitializedFunctions.h" />
|
||||
<ClInclude Include="Vector.h" />
|
||||
|
||||
@@ -13,11 +13,17 @@
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件\Profiler">
|
||||
<UniqueIdentifier>{092c2875-2b56-404b-977e-a9b4aa67c134}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Profiler\Profiler.cpp">
|
||||
<Filter>头文件\Profiler</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="TypeTraits.h">
|
||||
@@ -44,5 +50,8 @@
|
||||
<ClInclude Include="Algorithm.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Profiler\Profiler.h">
|
||||
<Filter>头文件\Profiler</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -69,22 +69,22 @@ namespace TinySTL{
|
||||
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
||||
Size n, const T& x, _true_type);
|
||||
template<class ForwardIterator, class Size, class T>
|
||||
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
||||
ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
|
||||
Size n, const T& x, _false_type);
|
||||
|
||||
template<class ForwardIterator, class Size, class T>
|
||||
inline ForwardIterator uninitialized_fill_n(ForwardIterator first,
|
||||
Size n, const T& x){
|
||||
typedef typename _type_traits<T>::is_POD_type isPODType;
|
||||
return _uninitialized_n_fill_aux(first, n, x, isPODType());
|
||||
return _uninitialized_fill_n_aux(first, n, x, isPODType());
|
||||
}
|
||||
template<class ForwardIterator, class Size, class T>
|
||||
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
||||
ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
|
||||
Size n, const T& x, _true_type){
|
||||
return fill_n(first, n, x);
|
||||
}
|
||||
template<class ForwardIterator, class Size, class T>
|
||||
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
||||
ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
|
||||
Size n, const T& x, _false_type){
|
||||
int i = 0;
|
||||
for (; i != n; ++i){
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace TinySTL{
|
||||
template<class InputIterator>
|
||||
void allocateAndCopy(InputIterator first, InputIterator last){
|
||||
start_ = dataAllocator::allocate(last - first);
|
||||
finish_ = uninitialized_copy(first, last, start_);
|
||||
finish_ = TinySTL::uninitialized_copy(first, last, start_);
|
||||
endOfStorage_ = finish_;
|
||||
}
|
||||
|
||||
@@ -171,13 +171,13 @@ namespace TinySTL{
|
||||
allocateAndCopy(first, last);
|
||||
}
|
||||
template<class Integer>
|
||||
void vector_aux(Integer n, Integer value, std::true_type){
|
||||
void vector_aux(Integer n, const value_type& value, std::true_type){
|
||||
allocateAndFillN(n, value);
|
||||
}
|
||||
template<class InputIterator>
|
||||
void insert_aux(iterator position, InputIterator first, InputIterator last, std::false_type);
|
||||
template<class Integer>
|
||||
void insert_aux(iterator position, Integer n, Integer value, std::true_type);
|
||||
void insert_aux(iterator position, Integer n, const value_type& value, std::true_type);
|
||||
template<class InputIterator>
|
||||
void reallocateAndCopy(iterator position, InputIterator first, InputIterator last);
|
||||
void reallocateAndFillN(iterator position, const size_type& n, const value_type& val);
|
||||
@@ -247,9 +247,9 @@ namespace TinySTL{
|
||||
|
||||
T *newStart = dataAllocator::allocate(newCapacity);
|
||||
T *newEndOfStorage = newStart + newCapacity;
|
||||
T *newFinish = uninitialized_copy(begin(), position, newStart);
|
||||
newFinish = uninitialized_copy(first, last, newFinish);
|
||||
newFinish = uninitialized_copy(position, end(), newFinish);
|
||||
T *newFinish = TinySTL::uninitialized_copy(begin(), position, newStart);
|
||||
newFinish = TinySTL::uninitialized_copy(first, last, newFinish);
|
||||
newFinish = TinySTL::uninitialized_copy(position, end(), newFinish);
|
||||
|
||||
destroyAndDeallocateAll();
|
||||
start_ = newStart;
|
||||
@@ -262,9 +262,9 @@ namespace TinySTL{
|
||||
|
||||
T *newStart = dataAllocator::allocate(newCapacity);
|
||||
T *newEndOfStorage = newStart + newCapacity;
|
||||
T *newFinish = uninitialized_copy(begin(), position, newStart);
|
||||
newFinish = uninitialized_fill_n(newFinish, n, val);
|
||||
newFinish = uninitialized_copy(position, end(), newFinish);
|
||||
T *newFinish = TinySTL::uninitialized_copy(begin(), position, newStart);
|
||||
newFinish = TinySTL::uninitialized_fill_n(newFinish, n, val);
|
||||
newFinish = TinySTL::uninitialized_copy(position, end(), newFinish);
|
||||
|
||||
destroyAndDeallocateAll();
|
||||
start_ = newStart;
|
||||
@@ -285,7 +285,7 @@ namespace TinySTL{
|
||||
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back
|
||||
*(tempPtr + locationNeed) = *tempPtr;
|
||||
}
|
||||
uninitialized_copy(first, last, position);
|
||||
TinySTL::uninitialized_copy(first, last, position);
|
||||
finish_ += locationNeed;
|
||||
}else{
|
||||
reallocateAndCopy(position, first, last);
|
||||
@@ -293,7 +293,7 @@ namespace TinySTL{
|
||||
}
|
||||
template<class T, class Alloc>
|
||||
template<class Integer>
|
||||
void vector<T, Alloc>::insert_aux(iterator position, Integer n, Integer value, std::true_type){
|
||||
void vector<T, Alloc>::insert_aux(iterator position, Integer n, const value_type& value, std::true_type){
|
||||
assert(n != 0);
|
||||
difference_type locationLeft = endOfStorage_ - finish_; // the size of left storage
|
||||
difference_type locationNeed = n;
|
||||
@@ -303,7 +303,7 @@ namespace TinySTL{
|
||||
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back
|
||||
*(tempPtr + locationNeed) = *tempPtr;
|
||||
}
|
||||
uninitialized_fill_n(position, n, value);
|
||||
TinySTL::uninitialized_fill_n(position, n, value);
|
||||
finish_ += locationNeed;
|
||||
}
|
||||
else{
|
||||
@@ -317,7 +317,7 @@ namespace TinySTL{
|
||||
}
|
||||
template<class T, class Alloc>
|
||||
void vector<T, Alloc>::insert(iterator position, const size_type& n, const value_type& val){
|
||||
insert_aux(position, n, val, typename std::is_integral<value_type>::type());
|
||||
insert_aux(position, n, val, typename std::is_integral<size_type>::type());
|
||||
}
|
||||
template<class T, class Alloc>
|
||||
typename vector<T, Alloc>::iterator vector<T, Alloc>::insert(iterator position, const value_type& val){
|
||||
|
||||
@@ -15,16 +15,16 @@ using namespace TinySTL::Profiler;
|
||||
|
||||
int main(){
|
||||
|
||||
int array[100000] = { 1 };
|
||||
std::vector<int> vec;
|
||||
//TinySTL::vector<int> vec;
|
||||
//std::vector<std::string> vec;
|
||||
//TinySTL::vector<std::string> vec;
|
||||
TinySTL::vector<int> vec;
|
||||
ProfilerInstance::start();
|
||||
int i = 0;
|
||||
for (; i != 10000000; ++i){
|
||||
//vec.insert(vec.end(), array, array + 1);
|
||||
for (; i != 10000; ++i){
|
||||
//vec.push_back(std::string("zouxiaohang"));
|
||||
vec.push_back(i);
|
||||
}
|
||||
//vec.insert(vec.end(), array, array + 100000);
|
||||
//for (auto i : vec){ cout << i << endl; }
|
||||
ProfilerInstance::finish();
|
||||
ProfilerInstance::dumpDuringTime();
|
||||
system("pause");
|
||||
|
||||
Reference in New Issue
Block a user