增加vector的逻辑比较操作
This commit is contained in:
@@ -106,6 +106,10 @@ namespace TinySTL{
|
|||||||
destroyAndDeallocateAll();
|
destroyAndDeallocateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//<2F>Ƚϲ<C8BD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
bool operator == (const vector& v);
|
||||||
|
bool operator != (const vector& v);
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
iterator begin(){ return iterator(start_); }
|
iterator begin(){ return iterator(start_); }
|
||||||
iterator end(){ return iterator(finish_); }
|
iterator end(){ return iterator(finish_); }
|
||||||
@@ -194,6 +198,11 @@ namespace TinySTL{
|
|||||||
size_type newCapacity = (oldCapacity != 0 ? (oldCapacity + res) : 1);
|
size_type newCapacity = (oldCapacity != 0 ? (oldCapacity + res) : 1);
|
||||||
return newCapacity;
|
return newCapacity;
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
template<class T, class Alloc>
|
||||||
|
friend bool operator == (const vector<T, Alloc>& v1, const vector<T, Alloc>& v2);
|
||||||
|
template<class T, class Alloc>
|
||||||
|
friend bool operator != (const vector<T, Alloc>& v1, const vector<T, Alloc>& v2);
|
||||||
};// end of class vector
|
};// end of class vector
|
||||||
|
|
||||||
//***********************<2A><><EFBFBD>죬<EFBFBD><ECA3AC><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***********************
|
//***********************<2A><><EFBFBD>죬<EFBFBD><ECA3AC><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***********************
|
||||||
@@ -379,6 +388,34 @@ namespace TinySTL{
|
|||||||
void vector<T, Alloc>::push_back(const value_type& value){
|
void vector<T, Alloc>::push_back(const value_type& value){
|
||||||
insert(end(), value);
|
insert(end(), value);
|
||||||
}
|
}
|
||||||
|
//***********<2A><EFBFBD><DFBC>Ƚϲ<C8BD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************
|
||||||
|
template<class T, class Alloc>
|
||||||
|
bool vector<T, Alloc>::operator == (const vector& v){
|
||||||
|
if (size() != v.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
auto ptr1 = start_;
|
||||||
|
auto ptr2 = v.start_;
|
||||||
|
for (; ptr1 != finish_ && ptr2 != v.finish_; ++ptr1, ++ptr2){
|
||||||
|
if (*ptr1 != *ptr2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class T, class Alloc>
|
||||||
|
bool vector<T, Alloc>::operator != (const vector& v){
|
||||||
|
return !(*this == v);
|
||||||
|
}
|
||||||
|
template<class T, class Alloc>
|
||||||
|
bool operator == (const vector<T, Alloc>& v1, const vector<T, Alloc>& v2){
|
||||||
|
return v1 == v2;
|
||||||
|
}
|
||||||
|
template<class T, class Alloc>
|
||||||
|
bool operator != (const vector<T, Alloc>& v1, const vector<T, Alloc>& v2){
|
||||||
|
return !(v1 == v2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user