Skip to content
Snippets Groups Projects
vector.hpp 1.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * vector.hpp
     *
     * Created on: Feb 28, 2014
     * Author: Jan Travnicek
     */
    
    #ifndef __VECTOR_HPP_
    #define __VECTOR_HPP_
    
    namespace std {
    
    
    template< class T , class ... Ts >
    std::ostream& operator<<(std::ostream& out, const std::vector<T, Ts ...>& vector) {
    
    	out << "[";
    
    	bool first = true;
    
    	for(const T& item : vector) {
    		if(!first) out << ", ";
    		first = false;
    		out << item;
    	}
    
    	out << "]";
    	return out;
    }
    
    
    template<class T, class ... Ts>
    struct compare<vector<T, Ts ...>> {
    	int operator()(const vector<T, Ts...>& first, const vector<T, Ts...>& second) const {
    
    		if(first.size() < second.size()) return -1;
    		if(first.size() > second.size()) return 1;
    
    
    		static compare<typename std::decay < T >::type > 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;
    	}
    };
    
    
    template < class T, class ... Ts >
    string to_string ( const std::vector < T, Ts ... > & value ) {
    	std::stringstream ss;
    	ss << value;
    	return ss.str();
    }
    
    
    } /* namespace std */
    
    #endif /* __VECTOR_HPP_ */