Skip to content

Commit

Permalink
renew template codes
Browse files Browse the repository at this point in the history
  • Loading branch information
fura2 committed Jul 15, 2023
1 parent 3716035 commit f09b66e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 31 deletions.
31 changes: 0 additions & 31 deletions library/template.hpp

This file was deleted.

6 changes: 6 additions & 0 deletions library/template/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "template.hpp"

int main() {

return 0;
}
56 changes: 56 additions & 0 deletions library/template/template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define impl_overload4(a, b, c, d, e, ...) e
#define impl_overload5(a, b, c, d, e, f, ...) f
#define impl_overload6(a, b, c, d, e, f, g, ...) g

#define impl_rep4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define impl_rep3(i, a, b) impl_rep4(i, a, b, 1)
#define impl_rep2(i, n) impl_rep3(i, 0, n)
#define impl_rep1(n) for (int _ = 0; _ < (n); ++_)
#define rep(...) impl_overload4(__VA_ARGS__, impl_rep4, impl_rep3, impl_rep2, impl_rep1)(__VA_ARGS__)

#define impl_rrep4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define impl_rrep3(i, a, b) _rrep4(i, a, b, 1)
#define impl_rrep2(i, n) _rrep3(i, 0, n)
#define rrep(...) impl_overload4(__VA_ARGS__, impl_rrep4, impl_rrep3, impl_rrep2)(__VA_ARGS__)

#define all(v) std::begin(v), std::end(v)

template<typename T>
constexpr int bit(T x, unsigned int k) { return (x >> k) & 1; }

template<typename C>
constexpr long ssize(const C& c) { return std::size(c); } // workaround until C++20

void yesno(bool b) { std::cout << (b ? "Yes" : "No") << "\n"; }
void yes() { yesno(true); }
void no() { yesno(false); }

struct Setup {
Setup() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(11);
}
} _setup;

#ifdef LOCAL
#include "template_local.hpp"
#else
#define show(...) ;
#endif

using uint = unsigned int;
using lint = long long;
using ulint = unsigned long long;

using namespace std;

#endif // TEMPLATE_HPP
74 changes: 74 additions & 0 deletions library/template/template_local.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef TEMPLATE_LOCAL_HPP
#define TEMPLATE_LOCAL_HPP

#include "template.hpp"

#define impl_show1(a) { std::clog << #a << " = " << a << endl; }
#define impl_show2(a, ...) { std::clog << #a << " = " << a << ", "; impl_show1(__VA_ARGS__); }
#define impl_show3(a, ...) { std::clog << #a << " = " << a << ", "; impl_show2(__VA_ARGS__); }
#define impl_show4(a, ...) { std::clog << #a << " = " << a << ", "; impl_show3(__VA_ARGS__); }
#define impl_show5(a, ...) { std::clog << #a << " = " << a << ", "; impl_show4(__VA_ARGS__); }
#define impl_show6(a, ...) { std::clog << #a << " = " << a << ", "; impl_show5(__VA_ARGS__); }
#define show(...) { std::clog << "\033[33m"; \
impl_overload6(__VA_ARGS__, impl_show6, impl_show5, impl_show4, impl_show3, impl_show2, impl_show1)(__VA_ARGS__) \
std::clog << "\033[0m" << std::flush; }

template<class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}

template<class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
os << "{";
bool first = true;
for (const auto& e : s) {
if (!first) os << ", ";
first = false;
os << e;
}
os << "}";
return os;
}

template<class T>
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T>& s) {
os << "{";
bool first = true;
for (const auto& e : s) {
if (!first) os << ", ";
first = false;
os << e;
}
os << "}";
return os;
}

template<class T>
std::ostream& operator<<(std::ostream& os, const std::multiset<T>& s) {
os << "{";
bool first = true;
for (const auto& e : s) {
if (!first) os << ", ";
first = false;
os << e;
}
os << "}";
return os;
}

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << "[";
bool first = true;
for (const auto& e : v) {
if (!first) os << ", ";
first = false;
os << e;
}
os << "]";
return os;
}

#endif // TEMPLATE_LOCAL_HPP

0 comments on commit f09b66e

Please sign in to comment.