- done/skip/undo accept unique prefixes like every other command - builds define LOCAL (-I repo root): the template includes debugging.h and enables DBG/printV only locally, so main.cpp is submittable as-is - run/build/test --debug (or USACO_DEBUG=1): ASan/UBSan + _GLIBCXX_DEBUG - list/stats date problems by git history, not mtimes reset by checkouts - template/tpl is now an alias of reset (which gains -y); fixes template dropping the STDIO line - run shows <io>.out via detect_io instead of the first *.out - debugging.h: size_t loop indices (no -Wsign-compare noise) - zsh completion for i/cat/copy; README covers test, io, reset, --debug - ignore a.out Co-Authored-By: Claude Opus 5.5 <[email protected]>
172 lines
4.5 KiB
C++
172 lines
4.5 KiB
C++
#include <deque>
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
template <typename T1, typename T2>
|
|
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &pair);
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::vector<T> &vec);
|
|
|
|
template <typename T, size_t SZ>
|
|
std::ostream &operator<<(std::ostream &out, const std::array<T, SZ> &arr);
|
|
|
|
template <typename T, typename C, typename A>
|
|
std::ostream &operator<<(std::ostream &out, const std::set<T, C, A> &set);
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::multiset<T> &set);
|
|
|
|
template <typename T1, typename T2>
|
|
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map);
|
|
|
|
template <typename T1, typename T2>
|
|
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &pair) {
|
|
return out << '(' << pair.first << ", " << pair.second << ')';
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::vector<T> &vec) {
|
|
if (vec.empty()) {
|
|
out << "[]";
|
|
return out;
|
|
}
|
|
out << '[';
|
|
for (size_t i = 0; i < vec.size() - 1; i++) {
|
|
out << vec[i] << ", ";
|
|
}
|
|
return out << vec.back() << ']';
|
|
}
|
|
|
|
template <typename T, size_t SZ>
|
|
std::ostream &operator<<(std::ostream &out, const std::array<T, SZ> &arr) {
|
|
if (SZ == 0) {
|
|
out << "[]";
|
|
return out;
|
|
}
|
|
out << '[';
|
|
for (size_t i = 0; i < SZ - 1; i++) {
|
|
out << arr[i] << ", ";
|
|
}
|
|
return out << arr.back() << ']';
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::deque<T> &deq) {
|
|
if (deq.empty()) {
|
|
out << "[]";
|
|
return out;
|
|
}
|
|
out << '[';
|
|
for (size_t i = 0; i < deq.size() - 1; i++) {
|
|
out << deq[i] << ", ";
|
|
}
|
|
return out << deq.back() << ']';
|
|
}
|
|
|
|
template <typename T1, typename T2>
|
|
std::ostream &operator<<(std::ostream &out,
|
|
const std::unordered_map<T1, T2> &map) {
|
|
out << '{';
|
|
for (auto it = map.begin(); it != map.end(); it++) {
|
|
std::pair<T1, T2> element = *it;
|
|
out << element.first << ": " << element.second;
|
|
if (std::next(it) != map.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
template <typename T1, typename T2>
|
|
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map) {
|
|
out << '{';
|
|
for (auto it = map.begin(); it != map.end(); it++) {
|
|
std::pair<T1, T2> element = *it;
|
|
out << element.first << ": " << element.second;
|
|
if (std::next(it) != map.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::unordered_set<T> &set) {
|
|
out << '{';
|
|
for (auto it = set.begin(); it != set.end(); it++) {
|
|
T element = *it;
|
|
out << element;
|
|
if (std::next(it) != set.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out, const std::multiset<T> &set) {
|
|
out << '{';
|
|
for (auto it = set.begin(); it != set.end(); it++) {
|
|
T element = *it;
|
|
out << element;
|
|
if (std::next(it) != set.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream &operator<<(std::ostream &out,
|
|
const std::unordered_multiset<T> &set) {
|
|
out << '{';
|
|
for (auto it = set.begin(); it != set.end(); it++) {
|
|
T element = *it;
|
|
out << element;
|
|
if (std::next(it) != set.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
template <typename T, typename C, typename A>
|
|
std::ostream &operator<<(std::ostream &out, const std::set<T, C, A> &set) {
|
|
out << '{';
|
|
for (auto it = set.begin(); it != set.end(); it++) {
|
|
T element = *it;
|
|
out << element;
|
|
if (std::next(it) != set.end()) {
|
|
out << ", ";
|
|
}
|
|
}
|
|
return out << '}';
|
|
}
|
|
|
|
// Source: https://stackoverflow.com/a/31116392/12128483
|
|
template <typename Type, unsigned N, unsigned Last> struct TuplePrinter {
|
|
static void print(std::ostream &out, const Type &value) {
|
|
out << std::get<N>(value) << ", ";
|
|
TuplePrinter<Type, N + 1, Last>::print(out, value);
|
|
}
|
|
};
|
|
|
|
template <typename Type, unsigned N> struct TuplePrinter<Type, N, N> {
|
|
static void print(std::ostream &out, const Type &value) {
|
|
out << std::get<N>(value);
|
|
}
|
|
};
|
|
|
|
template <typename... Types>
|
|
std::ostream &operator<<(std::ostream &out, const std::tuple<Types...> &value) {
|
|
out << '(';
|
|
TuplePrinter<std::tuple<Types...>, 0, sizeof...(Types) - 1>::print(out,
|
|
value);
|
|
return out << ')';
|
|
}
|