2017-04-26 02:50:03 +00:00
|
|
|
#pragma once
|
2017-02-14 19:14:34 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-03-23 19:38:17 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::pair<K, V> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "pair{" << what.first << ", " << what.second << "}";
|
|
|
|
return stream;
|
2017-03-23 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 19:14:34 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2017-03-23 19:38:17 +00:00
|
|
|
void dumpContainer(std::ostream & stream, const T & container)
|
2017-02-14 19:14:34 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "{";
|
|
|
|
bool first = true;
|
|
|
|
for (const auto & elem : container)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
stream << ", ";
|
|
|
|
first = false;
|
|
|
|
stream << elem;
|
|
|
|
}
|
|
|
|
stream << "}";
|
2017-03-23 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::vector<T> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "vector(size = " << what.size() << ", capacity = " << what.capacity() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-02-14 19:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
template <typename T, size_t N>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::array<T, N> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "array<" << what.size() << ">";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-02-14 19:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::map<K, V> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "map(size = " << what.size() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-02-14 19:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
template <typename K, typename V>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::unordered_map<K, V> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "unordered_map(size = " << what.size() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-02-14 19:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 19:38:17 +00:00
|
|
|
#include <set>
|
2017-02-14 19:14:34 +00:00
|
|
|
|
2017-03-23 19:38:17 +00:00
|
|
|
template <typename K>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::set<K> & what)
|
2017-02-14 19:14:34 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "set(size = " << what.size() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-02-14 19:14:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 19:38:17 +00:00
|
|
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::unordered_set<K> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "unordered_set(size = " << what.size() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
2017-03-23 19:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-26 02:50:03 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::list<K> & what)
|
|
|
|
{
|
|
|
|
stream << "list(size = " << what.size() << ")";
|
|
|
|
dumpContainer(stream, what);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-21 19:08:09 +00:00
|
|
|
#include <ratio>
|
|
|
|
|
|
|
|
template <std::intmax_t Num, std::intmax_t Denom>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::ratio<Num, Denom> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "ratio<Num=" << Num << ", Denom=" << Denom << ">";
|
|
|
|
return stream;
|
2017-03-21 19:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
template <class clock, class duration>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::chrono::duration<clock, duration> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "chrono::duration<clock=" << clock() << ", duration=" << duration() << ">{" << what.count() << "}";
|
|
|
|
return stream;
|
2017-03-21 19:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class clock, class duration>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::chrono::time_point<clock, duration> & what)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
stream << "chrono::time_point{" << what.time_since_epoch() << "}";
|
|
|
|
return stream;
|
2017-03-21 19:08:09 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 19:14:34 +00:00
|
|
|
|
2017-04-26 02:50:03 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::shared_ptr<T> & what)
|
|
|
|
{
|
2017-04-28 18:57:26 +00:00
|
|
|
stream << "shared_ptr(use_count = " << what.use_count() << ") {";
|
2017-04-26 02:50:03 +00:00
|
|
|
if (what)
|
|
|
|
stream << *what;
|
|
|
|
else
|
|
|
|
stream << "nullptr";
|
|
|
|
stream << "}";
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 18:57:26 +00:00
|
|
|
#include <experimental/optional>
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
std::ostream & operator<<(std::ostream & stream, const std::experimental::optional<T> & what)
|
|
|
|
{
|
|
|
|
stream << "optional{";
|
|
|
|
if (what)
|
|
|
|
stream << *what;
|
|
|
|
else
|
|
|
|
stream << "empty";
|
|
|
|
stream << "}";
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-14 19:14:34 +00:00
|
|
|
// TODO: add more types
|