mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
iostream_debug_helpers: improvement [#CLICKHOUSE-2901].
This commit is contained in:
parent
6042f1d5f9
commit
02c2bb926f
@ -1,80 +1,5 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <typename T>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::vector<T> & what)
|
||||
{
|
||||
stream << "vector(size = " << what.size() << ", capacity = " << what.capacity() << "){";
|
||||
bool first = true;
|
||||
for (const auto & i : what)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
first = false;
|
||||
stream << i;
|
||||
}
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <array>
|
||||
|
||||
template <typename T, size_t N>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::array<T, N> & what)
|
||||
{
|
||||
stream << "array<" << what.size() << ">{";
|
||||
bool first = true;
|
||||
for (const auto & i : what)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
first = false;
|
||||
stream << i;
|
||||
}
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::map<K, V> & what)
|
||||
{
|
||||
stream << "map(size = " << what.size() << "){";
|
||||
bool first = true;
|
||||
for (const auto & i : what)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
first = false;
|
||||
stream << i.first << ": " << i.second;
|
||||
}
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::unordered_map<K, V> & what)
|
||||
{
|
||||
stream << "unordered_map(size = " << what.size() << "){";
|
||||
bool first = true;
|
||||
for (const auto & i : what)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
first = false;
|
||||
stream << i.first << ": " << i.second;
|
||||
}
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <utility>
|
||||
|
||||
@ -85,6 +10,89 @@ std::ostream & operator<<(std::ostream & stream, const std::pair<K, V> & what)
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void dumpContainer(std::ostream & stream, const T & container)
|
||||
{
|
||||
stream << "{";
|
||||
bool first = true;
|
||||
for (const auto & elem : container)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
first = false;
|
||||
stream << elem;
|
||||
}
|
||||
stream << "}";
|
||||
}
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <typename T>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::vector<T> & what)
|
||||
{
|
||||
stream << "vector(size = " << what.size() << ", capacity = " << what.capacity() << ")";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <array>
|
||||
|
||||
template <typename T, size_t N>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::array<T, N> & what)
|
||||
{
|
||||
stream << "array<" << what.size() << ">";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::map<K, V> & what)
|
||||
{
|
||||
stream << "map(size = " << what.size() << ")";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
template <typename K, typename V>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::unordered_map<K, V> & what)
|
||||
{
|
||||
stream << "unordered_map(size = " << what.size() << ")";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <set>
|
||||
|
||||
template <typename K>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::set<K> & what)
|
||||
{
|
||||
stream << "set(size = " << what.size() << ")";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
template <typename K>
|
||||
std::ostream & operator<<(std::ostream & stream, const std::unordered_set<K> & what)
|
||||
{
|
||||
stream << "unordered_set(size = " << what.size() << ")";
|
||||
dumpContainer(stream, what);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
#include <ratio>
|
||||
|
||||
template <std::intmax_t Num, std::intmax_t Denom>
|
||||
|
Loading…
Reference in New Issue
Block a user