修复vector当对象是std::string时的构造二义性bug
This commit is contained in:
@@ -90,7 +90,7 @@ namespace TinySTL{
|
|||||||
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
|
||||||
Size n, const T& x, _false_type){
|
Size n, const T& x, _false_type){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i != n;){
|
for (; i != n; ++i){
|
||||||
construct((first + i), x);
|
construct((first + i), x);
|
||||||
}
|
}
|
||||||
return (first + i);
|
return (first + i);
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace TinySTL{
|
|||||||
private:
|
private:
|
||||||
void allocateAndFillN(const size_type n, const value_type& value){
|
void allocateAndFillN(const size_type n, const value_type& value){
|
||||||
start_ = dataAllocator::allocate(n);
|
start_ = dataAllocator::allocate(n);
|
||||||
uninitialized_fill_n(start_, n, value);
|
TinySTL::uninitialized_fill_n(start_, n, value);
|
||||||
finish_ = endOfStorage_ = start_ + n;
|
finish_ = endOfStorage_ = start_ + n;
|
||||||
}
|
}
|
||||||
template<class InputIterator>
|
template<class InputIterator>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "Allocator.h"
|
#include "Allocator.h"
|
||||||
#include "Construct.h"
|
#include "Construct.h"
|
||||||
@@ -11,12 +12,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int array[3] = { 1, 2, 3 };
|
TinySTL::vector<std::string> svec(10, "hello world");
|
||||||
TinySTL::vector<int> vec(array, array + 3);
|
for (auto s : svec){ cout << s << endl; }
|
||||||
//TinySTL::vector<int> vec(3, 1); -> error C2019
|
|
||||||
cout << *(vec.begin()) << endl;
|
|
||||||
cout << *(++vec.begin()) << endl;
|
|
||||||
cout << *(--vec.end()) << endl;
|
|
||||||
system("pause");
|
system("pause");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user