-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
53 lines (43 loc) · 1004 Bytes
/
debug.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
#include <cstdio>
#include <iostream>
#include <ostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <array>
template <typename A>
struct fake_iterable
{
A &_begin;
A &_end;
fake_iterable(A &__begin, A &__end) : _begin(__begin), _end(__end) {}
A &begin() { return _begin; }
A &end()
{
return _end;
}
};
template <typename R>
struct print
{
R &r;
explicit print(R &_r) : r(_r) {}
};
template <typename A>
print<fake_iterable<A>> make_print(A &begin, A &end) { return print(*(new fake_iterable(begin, end))); }
template <typename A>
print<fake_iterable<A>> make_print(A begin, A end) { return print(*(new fake_iterable(begin, end))); }
template <typename R>
std::ostream &operator<<(std::ostream &os,
const print<R> &vector)
{
// Printing all the elements
// using <<
os << "[";
for (auto element : vector.r)
{
os << element << ", ";
}
os << "]";
return os;
}