Kylin/Universal/StreamFormat.h

48 lines
1.3 KiB
C
Raw Normal View History

2023-07-21 10:47:31 +08:00
#ifndef STREAMFORMAT_H
#define STREAMFORMAT_H
#include <chrono>
#include <list>
#include <ostream>
#include <vector>
namespace std {
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &stream, const std::pair<T1, T2> &element) {
stream << "[" << element.first << "," << element.second << "]";
return stream;
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &element) {
stream << "[";
for (const auto &e : element) {
stream << e << ",";
}
stream << "]";
return stream;
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const std::list<T> &element) {
stream << "[";
for (const auto &e : element) {
stream << e << ",";
}
stream << "]";
return stream;
}
std::ostream &operator<<(std::ostream &stream, const std::chrono::milliseconds &element);
std::ostream &operator<<(std::ostream &stream, const std::chrono::microseconds &element);
} // namespace std
template <typename T1, typename T2>
bool operator==(const std::pair<T1, T2> &lhs, const std::pair<T1, T2> &rhs) {
return lhs.first == rhs.first && lhs.second == rhs.second;
}
#include "StreamFormat.inl"
#endif // STREAMFORMAT_H