修复vector当对象是std::string时的构造二义性bug

This commit is contained in:
邹晓航
2014-09-20 20:35:06 +08:00
parent 4ddc317978
commit 74bf3e2ec7
3 changed files with 6 additions and 9 deletions

View File

@@ -90,7 +90,7 @@ namespace TinySTL{
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
Size n, const T& x, _false_type){
int i = 0;
for (; i != n;){
for (; i != n; ++i){
construct((first + i), x);
}
return (first + i);

View File

@@ -151,7 +151,7 @@ namespace TinySTL{
private:
void allocateAndFillN(const size_type n, const value_type& value){
start_ = dataAllocator::allocate(n);
uninitialized_fill_n(start_, n, value);
TinySTL::uninitialized_fill_n(start_, n, value);
finish_ = endOfStorage_ = start_ + n;
}
template<class InputIterator>

View File

@@ -2,6 +2,7 @@
#include <memory>
#include <string>
#include <vector>
#include <utility>
#include "Allocator.h"
#include "Construct.h"
@@ -11,12 +12,8 @@
using namespace std;
int main(){
int array[3] = { 1, 2, 3 };
TinySTL::vector<int> vec(array, array + 3);
//TinySTL::vector<int> vec(3, 1); -> error C2019
cout << *(vec.begin()) << endl;
cout << *(++vec.begin()) << endl;
cout << *(--vec.end()) << endl;
TinySTL::vector<std::string> svec(10, "hello world");
for (auto s : svec){ cout << s << endl; }
system("pause");
return 0;
}
}