Skip to content

Commit

Permalink
update the == operator function for vector
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterzhao committed Jul 10, 2016
1 parent dec819c commit 5816da3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/vectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ namespace EasySTL {
//std::string new_EasySTL_vector = "new_EasySTL_vector";
//stdVec<std::string> v1(10, "zzz");
easyVec<std::string> v1 = {"1","2","3","4"};
easyVec<std::string> v2 = {"1","2","3","5"};
//EasySTL::Test::print_container(v1, "SGI_vector");
EasySTL::Test::print_container(v1, "construct");
if (v1 == v2) std::cout<<"equal" <<std::endl;
else std::cout<<"not equal" <<std::endl;
//EasySTL::Test::print_container(v1, "construct");

//easyVec<std::string> v3 = {"abc","cba","dca","ghj"};
//EasySTL::Test::print_container(v3, "v3");
Expand Down
10 changes: 10 additions & 0 deletions vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ namespace EasySTL {
size_type capacity() const { return size_type(end_of_storage_ - begin());}
bool empty() const { return begin() == end();}
reference operator[](size_type n) {return *(begin() + n);}
bool operator ==(const vector& other) const {
auto first1 = begin(), last1 = end();
auto first2 = other.begin(), last2 = other.end();
for (; first1 != last1 && first2 != last2; ++first1, ++first2){
if (*first1 != *first2)
return false;
}
return (first1 == last1 && first2 == last2);

}

vector() : start_(0), finish_(0), end_of_storage_(0) {}
vector(size_type n, const T& value) { fill_initialize(n, value);}
Expand Down

0 comments on commit 5816da3

Please sign in to comment.