1
0
Fork 0

allow logging more types

This commit is contained in:
jsteemann 2017-02-01 11:24:22 +01:00
parent fc5d7311b5
commit 4aa57b1cd1
1 changed files with 36 additions and 5 deletions

View File

@ -75,20 +75,51 @@ class LoggerStream {
}
template <typename T>
LoggerStream& operator<<(T obj) {
LoggerStream& operator<<(T const& obj) {
_out << obj;
return *this;
}
template <typename T>
LoggerStream& operator<<(std::vector<T> const& v) {
for (auto const& i : v) _out << i << " ";
LoggerStream& operator<<(std::vector<T> const& obj) {
_out << '[';
size_t i = 0;
size_t const n = obj.size();
for (auto const& it : obj) {
if (++i < n) {
_out << it << ", ";
}
}
_out << ']';
return *this;
}
template <typename T>
LoggerStream& operator<<(std::unordered_set<T> const& us) {
for (auto const& i : us) _out << i;
LoggerStream& operator<<(std::unordered_set<T> const& obj) {
_out << '{';
size_t i = 0;
size_t const n = obj.size();
for (auto const& it : obj) {
if (++i < n) {
_out << it << ", ";
}
}
_out << '}';
return *this;
}
template <typename K, typename V>
LoggerStream& operator<<(std::unordered_map<K, V> const& obj) {
_out << '{';
size_t i = 0;
size_t n = obj.size();
for (auto const& it : obj) {
if (++i < n) {
_out << it << ", ";
}
_out << it.first << " => " << it.second;
}
_out << '}';
return *this;
}