diff options
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | vector.hpp | 58 |
2 files changed, 53 insertions, 7 deletions
@@ -6,6 +6,7 @@ int main() ft::vector<int> vec(10); ft::vector<int> other(vec); vec = other; + std::cout << (vec == other) << std::endl; other.assign(ft::vector<int>::size_type(5), 3); for (ft::vector<int>::size_type i = 0; i < other.size(); i++) std::cout << other.at(i) << std::endl; @@ -18,5 +19,6 @@ int main() other.pop_back(); for (ft::vector<int>::size_type i = 0; i < other.size(); i++) std::cout << other.at(i) << std::endl; + std::cout << (vec == other) << std::endl; return 0; } @@ -288,23 +288,67 @@ namespace ft { }; template<class T, class Alloc> void swap(vector<T,Alloc>& lhs, - vector<T,Alloc>& rhs); + vector<T,Alloc>& rhs) + { + lhs.swap(rhs); + } + template<class T, class Alloc> bool operator==(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + if (lhs.size() != rhs.size()) + return false; + for (typename vector<T,Alloc>::size_type i = 0; i < lhs.size(); i++) + if (lhs[i] != rhs[i]) + return false; + return true; + } + template<class T, class Alloc> bool operator!=(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + return !(lhs == rhs); + } + template<class T, class Alloc> bool operator<(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + const typename vector<T,Alloc>::size_type end + (lhs.size() < rhs.size() ? lhs.size() : rhs.size()); + for (typename vector<T,Alloc>::size_type i = 0; i < end; i++) { + if (lhs[i] < rhs[i]) + return true; + } + return lhs.size() < rhs.size(); + } + template<class T, class Alloc> bool operator<=(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + return !(lhs > rhs); + } + template<class T, class Alloc> bool operator>(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + const typename vector<T,Alloc>::size_type end + (lhs.size() < rhs.size() ? lhs.size() : rhs.size()); + for (typename vector<T,Alloc>::size_type i = 0; i < end; i++) { + if (lhs[i] > rhs[i]) + return true; + } + return lhs.size() > rhs.size(); + } + template<class T, class Alloc> bool operator>=(const vector<T,Alloc>& lhs, - const vector<T,Alloc>& rhs); + const vector<T,Alloc>& rhs) + { + return !(lhs < rhs); + } } |