-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
61 lines (56 loc) · 1.56 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <algorithm>
#include <bitset>
#include <cctype>
#include <charconv>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <ranges>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>
using vs = std::vector<std::string>;
#define ASSERT_EXPR(expr, err) \
if (!(expr)) \
throw std::runtime_error((err));
namespace gb::advent2021 {
// Sad state of c++ where range based iteration with split_view is just
// impossible to work in gcc 11.3
std::vector<std::string_view> split(const std::string &sentence,
const std::string &delim) {
std::vector<std::string_view> vs{};
size_t s{0}, e{0};
auto it = sentence.begin();
while ((e = sentence.find(delim, s)) != std::string::npos) {
vs.emplace_back(std::string_view{it, std::next(it, (e - s))});
std::advance(it, (e - s) + delim.size());
s = e + delim.size();
}
return vs;
}
std::vector<std::string> readIn() {
std::vector<std::string> lines;
for (std::string l; getline(std::cin, l);) {
lines.emplace_back(l);
}
return lines;
}
void writeOut(std::string s) { std::cout << s << std::endl; }
} // namespace gb::advent2021