Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
vector.hpp 938 B
/*
 * vector.hpp
 *
 * Created on: Feb 28, 2014
 * Author: Jan Travnicek
 */

#ifndef __VECTOR_HPP_
#define __VECTOR_HPP_

namespace std {

template< class T , class Allocator >
std::ostream& operator<<(std::ostream& out, const std::vector<T, Allocator>& vector) {
	out << "[";

	bool first = true;
	for(const T& item : vector) {
		if(!first) out << ", ";
		first = false;
		out << item;
	}

	out << "]";
	return out;
}

template<class T, class Allocator>
struct compare<vector<T, Allocator>> {
	int operator()(const vector<T, Allocator>& first, const vector<T, Allocator>& second) const {
		if(first.size() < second.size()) return -1;
		if(first.size() > second.size()) return 1;

		compare<T> comp;
		for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
			int res = comp(*iterF, *iterS);
			if(res != 0) return res;
		}
		return 0;
	}
};

} /* namespace std */

#endif /* __VECTOR_HPP_ */