Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TinySTL/Detail/List.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace TinySTL{
auto node1 = lhs.head.p, node2 = rhs.head.p;
for (; node1 != lhs.tail.p && node2 != rhs.tail.p; node1 = node1->next, node2 = node2->next){
if (node1->data != node2->data)
break;
return false;
}
if (node1 == lhs.tail.p && node2 == rhs.tail.p)
return true;
Expand Down
13 changes: 11 additions & 2 deletions TinySTL/Detail/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ namespace TinySTL{
}
size_t string::find(const string& str, size_t pos) const{
size_t lengthOfS = str.size();
if (size() - pos < lengthOfS)
//if (size() - pos < lengthOfS)
// return npos;
if (size() < lengthOfS + pos)
return npos;
return find_aux(str.cbegin(), pos, lengthOfS, size());
}
Expand All @@ -262,6 +264,7 @@ namespace TinySTL{
}
size_t string::rfind(char c, size_t pos) const{
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
if (npos == pos) return npos;
for (auto cit = cbegin() + pos; cit >= cbegin(); --cit){
if (*cit == c)
return cit - cbegin();
Expand All @@ -288,10 +291,12 @@ namespace TinySTL{
//if (pos - 0 < lengthOfS)
// return npos;
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
if (npos == pos) return npos;
return rfind_aux(str.begin(), pos, lengthOfS, 0);
}
size_t string::rfind(const char* s, size_t pos) const{
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
if (npos == pos) return npos;
return rfind(s, pos, strlen(s));
}
size_t string::rfind(const char* s, size_t pos, size_t n) const{
Expand Down Expand Up @@ -377,7 +382,8 @@ namespace TinySTL{
return npos;
}
size_t string::find_first_not_of(char c, size_t pos) const{
for (size_t i = pos; i != size(); ++i){
//bug fix (if pos>size())
for (size_t i = pos; i < size(); ++i){
if ((*this)[i] != c)
return i;
}
Expand All @@ -386,6 +392,7 @@ namespace TinySTL{
size_t string::find_last_of(const string& str, size_t pos) const{
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
//return find_last_of(str.begin(), pos, pos + 1);
if (npos == pos) return npos;
return find_last_of(str.begin(), pos, str.size());
}
size_t string::find_last_of(const char* s, size_t pos) const{
Expand All @@ -412,11 +419,13 @@ namespace TinySTL{
size_t string::find_last_not_of(const string& str, size_t pos) const{
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
//return find_last_not_of(str.begin(), pos, size());
if (npos == pos) return npos;
return find_last_not_of(str.begin(), pos, str.size());
}
size_t string::find_last_not_of(const char* s, size_t pos) const{
pos = changeVarWhenEuqalNPOS(pos, size(), 1);
//return find_last_not_of(s, pos, pos + 1);
if (npos == pos) return npos;
return find_last_not_of(s, pos, strlen(s));
}
size_t string::find_last_not_of(const char* s, size_t pos, size_t n) const{
Expand Down
24 changes: 12 additions & 12 deletions TinySTL/Detail/Vector.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ namespace TinySTL{
}
else if (n > capacity()){
auto lengthOfInsert = n - size();
T *newStart = dataAllocator::allocate(getNewCapacity(lengthOfInsert));
//T *newStart = dataAllocator::allocate(getNewCapacity(lengthOfInsert));
T *newStart = dataAllocator::allocate(getNewCapacity(n));
T *newFinish = TinySTL::uninitialized_copy(begin(), end(), newStart);
newFinish = TinySTL::uninitialized_fill_n(newFinish, lengthOfInsert, val);

Expand All @@ -88,20 +89,19 @@ namespace TinySTL{
//***************�޸���������ز���**************************
template<class T, class Alloc>
typename vector<T, Alloc>::iterator vector<T, Alloc>::erase(iterator position){
return erase(position, position + 1);
if (position + 1 != end())
std::copy(position + 1, finish_, position);
auto tmp = finish_;
--finish_;
dataAllocator::destroy(tmp);
return position;
}
template<class T, class Alloc>
typename vector<T, Alloc>::iterator vector<T, Alloc>::erase(iterator first, iterator last){
//�����������
difference_type lenOfTail = end() - last;
//ɾȥ�Ķ�����Ŀ
difference_type lenOfRemoved = last - first;
finish_ = finish_ - lenOfRemoved;
for (; lenOfTail != 0; --lenOfTail){
auto temp = (last - lenOfRemoved);
*temp = *(last++);
}
return (first);
iterator pos = std::copy(last, finish_, first);
dataAllocator::destroy(pos, finish_);
finish_ = finish_ - (last - first);
return first;
}
template<class T, class Alloc>
template<class InputIterator>
Expand Down