-
Jan Trávníček authoredJan Trávníček authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
unordered_map.hpp 1.24 KiB
/*
* unordered_map.hpp
*
* Created on: Feb 28, 2014
* Author: Jan Travnicek
*/
#ifndef __UNORDERED_MAP_HPP_
#define __UNORDERED_MAP_HPP_
namespace std {
template< class T, class R, class ... Ts >
std::ostream& operator<<(std::ostream& out, const std::unordered_map<T, R, Ts ... >& map) {
out << "{";
bool first = true;
for(const std::pair<const T, R>& item : map) {
if(!first) out << ", ";
first = false;
out << item;
}
out << "}";
return out;
}
template<class T, class R, class ... Ts>
struct compare<unordered_map<T, R, Ts ...>> {
int operator()(const unordered_map<T, R, Ts ...>& first, const unordered_map<T, R, Ts ...>& second) const {
if(first.size() < second.size()) return -1;
if(first.size() > second.size()) return 1;
static compare<typename std::decay < R >::type > comp;
for(auto iter = first.begin(); iter != first.end(); ++iter) {
auto search = second.find(iter->first);
if(search == second.end()) return -1;
int res = comp(iter->second, search->second);
if(res != 0) return res;
}
return 0;
}
};
template < class T, class R >
string to_string ( const std::unordered_map < T, R > & value ) {
std::stringstream ss;
ss << value;
return ss.str();
}
} /* namespace std */
#endif /* __UNORDERED_MAP_HPP_ */