Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
cpp: deprecate many things
Browse files Browse the repository at this point in the history
C++ is no longer my language of choice for competitive programming. This
change removes everything that is not being used by the wider community.

Checkers, interactors, and validation routines still exist and will
remain.
  • Loading branch information
Riolku committed Jan 4, 2024
1 parent 2d621fb commit 0a8ab2a
Show file tree
Hide file tree
Showing 26 changed files with 34 additions and 4,535 deletions.
741 changes: 0 additions & 741 deletions build/generator.cpp

This file was deleted.

369 changes: 4 additions & 365 deletions build/identical_checker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Built with `init-template identical_checker_entry` on 2023-06-13
// Built with `init-template identical_checker_entry` on 2024-01-04
#include <algorithm>
#include <cmath>
#include <random>
Expand Down Expand Up @@ -34,155 +34,6 @@ using pii = pair<int, int>;

#define all(x) (x).begin(), (x).end()

namespace Printer {
FILE *stream = stdout;

void set_stream(FILE *st) { stream = st; }

// Simple Types
void print_impl(bool x) { fprintf(stream, "%d", x); }
void print_impl(int x) { fprintf(stream, "%d", x); }
void print_impl(ll x) { fprintf(stream, "%lld", x); }
void print_impl(size_t x) { fprintf(stream, "%lu", x); }
void print_impl(const char *x) { fprintf(stream, "%s", x); }
void print_impl(const string &x) { print_impl(x.c_str()); }
void print_impl(char x) { fprintf(stream, "%c", x); }

// Recursive types. First, declare all overloads
template <typename T> void print_impl(const T &);
template <typename A, typename B> void print_impl(const pair<A, B> &);
template <typename... Ts> void print_impl(const tuple<Ts...> &t);
template <typename T, typename Container> void print_impl(queue<T, Container>);
template <typename T, typename Container, typename Compare>
void print_impl(priority_queue<T, Container, Compare>);
template <typename T> void print_impl(const set<T> &);
template <typename T> void print_impl(const vector<T> &);
template <typename T, size_t size> void print_impl(const array<T, size> &);
template <typename T> void print_impl(const unordered_set<T> &);

// Recursive type definitions
template <typename T> void print_impl(const T &x) {
print_impl(x.get_printable());
}

template <typename A, typename B> void print_impl(const pair<A, B> &p) {
print_impl(p.first);
print_impl(' ');
print_impl(p.second);
}

template <size_t index, typename T>
typename enable_if<index == 0, void>::type print_tuple(const T &t) {}

template <size_t index, typename T>
typename enable_if<index == 1, void>::type print_tuple(const T &t) {
print_impl(get<tuple_size<T>() - index>(t));
}

template <size_t index, typename T>
typename enable_if<(index > 1), void>::type print_tuple(const T &t) {
print_impl(get<tuple_size<T>() - index>(t));
print_impl(' ');
print_tuple<index - 1>(t);
}

template <typename... Ts> void print_impl(const tuple<Ts...> &t) {
print_tuple<sizeof...(Ts)>(t);
}

template <typename T> void print_iterable(const T &arr) {
bool first = true;

for (auto x : arr) {
if (!first) {
print_impl(" ");
}
first = false;

print_impl(x);
}
}

template <typename T> void print_impl(const set<T> &arr) {
print_iterable(arr);
}
template <typename T> void print_impl(const vector<T> &arr) {
print_iterable(arr);
}
template <typename T> void print_impl(const unordered_set<T> &arr) {
print_iterable(arr);
}
template <typename T, size_t size> void print_impl(const array<T, size> &arr) {
print_iterable(arr);
}
template <typename T, typename Container>
void print_impl(queue<T, Container> q) {
vector<T> dummy;
dummy.reserve(q.size());
while (!q.empty()) {
dummy.push_back(move(q.front()));
q.pop_front();
}
print_impl(dummy);
}

template <typename T, typename Container, typename Compare>
void print_impl(priority_queue<T, Container, Compare> pq) {
vector<T> dummy;
dummy.reserve(pq.size());
while (!pq.empty()) {
dummy.push_back(move(pq.top()));
pq.pop();
}
print_impl(dummy);
}
// print_many helper
template <typename T> void print_many(const T &arg) { print_impl(arg); }
template <typename T, typename... Ts>
void print_many(const T &arg, Ts &&...args) {
print_impl(arg);
print_impl(' ');
print_many(forward<Ts>(args)...);
}

template <typename... Ts> void print(Ts &&...args) {
print_many(forward<Ts>(args)...);

print();
}
template <> void print() { fprintf(stream, "\n"); }
template <typename T> void print_map(const T &mp) {
for (auto p : mp) {
print(p);
}
}

template <typename R> void print_items(const R &r) {
for (auto x : r) {
print(x);
}
}

template <typename K, typename V>
void print_items(const unordered_map<K, V> &mp) {
print_map(mp);
}
template <typename K, typename V> void print_items(const map<K, V> &mp) {
print_map(mp);
}

template <typename T> void print_yes_no(const T &xs) {
for (const auto &x : xs)
print_yes_no(x);
}
template <> void print_yes_no(const bool &x) { print(x ? "YES" : "NO"); }
}; // namespace Printer

using Printer::print;
using Printer::print_items;
using Printer::print_yes_no;
using Printer::set_stream;

// modified from a template by wleung_bvg

class BaseReader {
Expand Down Expand Up @@ -412,221 +263,9 @@ template <typename Parent> class ExactWhitespaceMixin : public Parent {
using Parent::Parent;
};

template <typename T, int offset = 0> class List : public vector<T> {
public:
using vector<T>::vector;
List(vector<T> v) : vector<T>::vector(move(v)) {}
template <int other_offset>
List(List<T, other_offset> other) : vector<T>::vector(move(other)) {}
T &operator[](size_t x) { return this->at(x - offset); }
const T &operator[](size_t x) const { return this->at(x - offset); }

template <typename F> void for_each(F f) { ::for_each(all(*this), f); }
template <typename F> void for_each(F f) const { ::for_each(all(*this), f); }
template <typename F> void for_each_pair(F f) {
::for_each(all(*this), [&f](T &p) -> void {
decltype(p.first) &a = get<0>(p);
decltype(p.second) &b = get<1>(p);
f(a, b);
});
}
template <typename F> void for_each_pair(F f) const {
::for_each(all(*this), [&f](const T &p) -> void {
const decltype(p.first) &a = get<0>(p);
const decltype(p.second) &b = get<1>(p);
f(a, b);
});
}
template <typename F> void for_each_enumerate(F f) {
size_t i = offset;
for (auto it = this->begin(); it != this->end(); ++it) {
f(*it, i);
++i;
}
}
template <typename F> void for_each_enumerate(F f) const {
size_t i = offset;
for (auto it = this->begin(); it != this->end(); ++it) {
f(*it, i);
++i;
}
}
template <typename F> void for_each_adjacent(F f) const {
if (this->size() == 0)
return;
auto it1 = this->begin();
auto it2 = next(it1);
while (it2 != this->end()) {
f(*it1, *it2);
++it1;
++it2;
}
}
template <typename F> void for_each_adjacent(F f) {
if (this->size() == 0)
return;
auto it1 = this->begin();
auto it2 = next(it1);
while (it2 != this->end()) {
F(*it1, *it2);
++it1;
++it2;
}
}

List<T, offset> &operator+=(const List<T, offset> &other) {
for (const T &elem : other)
this->push_back(elem);
return *this;
}
List<T, offset> &operator+=(List<T, offset> &&other) {
for (auto &&elem : other)
this->push_back(move(elem));
return *this;
}
List<T, offset> operator+(const List<T, offset> &other) const & {
List<T, offset> ret(this->begin(), this->end());
return ret += other;
}
List<T, offset> operator+(List<T, offset> &&other) const & {
List<T, offset> ret(this->begin(), this->end());
return ret += move(other);
}
List<T, offset> operator+(const List<T, offset> &other) && {
return *this += other;
}
List<T, offset> operator+(List<T, offset> &&other) && {
return *this += move(other);
}

template <typename F> bool any_of(F f) const {
return ::any_of(all(*this), f);
}
template <typename F> bool all_of(F f) const {
return ::any_of(all(*this), f);
}

T max() const {
assert(this->size() > 0);
return *::max_element(this->begin(), this->end());
}
T max(const T &init) const {
if (this->size() == 0)
return init;
return max();
}
T max(T &&init) const {
if (this->size() == 0)
return move(init);
return max();
}

T min() const {
assert(this->size() > 0);
return *::min_element(this->begin(), this->end());
}
T min(const T &init) const {
if (this->size() == 0)
return init;
return min();
}
T min(T &&init) const {
if (this->size() == 0)
return move(init);
return min();
}

T sum(T start = T()) const {
return ::accumulate(this->begin(), this->end(), move(start));
}

List<T, offset> &sort() {
::sort(all(*this));
return *this;
}

List<T, offset> &reverse() {
::reverse(all(*this));
return *this;
}

template <typename F> List<T, offset> &map(F f) {
::transform(all(*this), this->begin(), f);
return *this;
}

template <typename F>
auto map_new(F f) const -> List<decltype(f(declval<T>())), offset> {
List<decltype(f(declval<T>())), offset> ret;
ret.reserve(this->size());
::transform(all(*this), back_inserter(ret), f);
return ret;
}

template <typename F>
auto map_adjacent_new(F f) const
-> List<decltype(f(declval<T>(), declval<T>())), offset> {
List<decltype(f(declval<T>(), declval<T>())), offset> ret;
if (this->size() == 0)
return ret;
ret.reserve(this->size() - 1);
auto it1 = this->begin();
auto it2 = next(it1);
while (it2 != this->end()) {
ret.push_back(f(*it1, *it2));
++it1;
++it2;
}
return ret;
}

const vector<T> &get_printable() const { return *this; }
};

template <int offset = 0, typename F>
auto generate(int N, F f) -> List<decltype(f()), offset> {
List<decltype(f()), offset> ret;
ret.reserve(N);
::generate_n(back_inserter(ret), N, move(f));
return ret;
}

template <typename T, int offset>
List<T, offset> interleave(List<T, offset> A, List<T, offset> B) {
assert(A.size() == B.size() || A.size() == B.size() + 1);
List<T, offset> ret;
ret.reserve(A.size() + B.size());

auto ait = A.begin();
auto bit = B.begin();

while (ait != A.end() && bit != B.end()) {
ret.push_back(*ait);
ret.push_back(*bit);
++ait;
++bit;
}

if (ait != A.end()) {
ret.push_back(*ait);
++ait;
}
assert(ait == A.end());
assert(bit == B.end());
return ret;
}

template <typename T, typename F> void exhaust_queue(queue<T> &q, F f) {
while (!q.empty()) {
T x(move(q.front()));
q.pop();
f(move(x));
}
}

void assert_permutation(const List<int, 1> &arr) {
List<int, 1> check(arr.size(), 0);
assert(arr.all_of([&check](int x) { return ++check[x] == 1; }));
void assert_permutation(const vector<int> &arr) {
vector<int> check(arr.size(), 0);
assert(std::all_of(arr.begin(), arr.end(), [&check](int x) { return ++check[x - 1] == 1; }));
}

class validator_out_of_range {};
Expand Down
Loading

0 comments on commit 0a8ab2a

Please sign in to comment.