-
Notifications
You must be signed in to change notification settings - Fork 9
/
formatting-with-manipulators.cpp
100 lines (69 loc) · 3.09 KB
/
formatting-with-manipulators.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <cmath>
#include <iostream>
#include <vector>
#include "../cpp-dump.hpp"
namespace cp = cpp_dump;
int main() {
std::clog << std::endl;
std::vector<std::vector<int>> some_huge_vector(100, std::vector<int>(100));
std::vector<std::vector<unsigned int>> unsigned_int_vector(100, std::vector<unsigned int>(100));
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 100; ++j) {
some_huge_vector[i][j] = ((i + 1) * 7 % 19 - 9) * ((j + 1) * 3 % 19 - 9);
unsigned_int_vector[i][j] = std::abs(some_huge_vector[i][j]);
}
}
// default: max_iteration_count = 16;
cpp_dump(some_huge_vector);
std::clog << "\n// manipulator-front-etc.png\n" << std::endl;
cpp_dump(some_huge_vector | cp::back(10) | cp::both_ends(5) | cp::dec(2));
std::clog << "\n// manipulator-index.png\n" << std::endl;
CPP_DUMP_SET_OPTION(max_iteration_count, 5);
cpp_dump(some_huge_vector | cp::dec(2) | cp::index());
std::clog << "\n// manipulator-int-style.png\n" << std::endl;
cpp_dump(0x3e8u | cp::bin(16, 4));
cpp_dump(0x3e8u | cp::oct(6, 3));
cpp_dump(0x3e8u | cp::hex(4, 2));
cpp_dump(0x3e8u | cp::dec(4));
std::clog << "\n// manipulator-int-style2.png\n" << std::endl;
auto &int_vector = unsigned_int_vector;
cpp_dump(int_vector | cp::front(2) | cp::bin(8));
cpp_dump(int_vector | cp::front(2) | cp::oct(3));
cpp_dump(int_vector | cp::front(2) | cp::dec(2));
cpp_dump(int_vector | cp::front(2) | cp::hex(2));
std::clog << "\n// manipulator-bin-etc.png\n" << std::endl;
auto &signed_int_vector = some_huge_vector;
cpp_dump(signed_int_vector | cp::front(2) | cp::hex(2));
cpp_dump(unsigned_int_vector | cp::front(2) | cp::hex(2));
cpp_dump(signed_int_vector | cp::front(2) | cp::dec(2));
cpp_dump(unsigned_int_vector | cp::front(2) | cp::dec(2));
std::clog << "\n// manipulator-ubin-etc.png\n" << std::endl;
cpp_dump(signed_int_vector | cp::front(2) | cp::uhex());
cpp_dump(unsigned_int_vector | cp::front(2) | cp::uhex(2));
cpp_dump(signed_int_vector | cp::front(2) | cp::udec(2));
cpp_dump(unsigned_int_vector | cp::front(2) | cp::udec(2));
std::clog << "\n// manipulator-format.png\n" << std::endl;
constexpr double pi = 3.14159265358979323846;
cpp_dump(pi | cp::format("%.10f"));
std::clog << "\n// manipulator-bw-boolnum.png\n" << std::endl;
std::vector<std::vector<bool>> bool_vector{
{true, false, true, true, false},
{false, false, false, true, true},
};
cpp_dump(bool_vector | cp::bw());
cpp_dump(bool_vector | cp::bw(true));
cpp_dump(bool_vector | cp::boolnum());
std::clog << "\n// manipulator-stresc.png\n" << std::endl;
cpp_dump("\a\t\\\"\n\x7f need to be escaped.");
cpp_dump("\a\t\\\"\n\x7f need to be escaped." | cp::stresc());
std::clog << "\n// manipulator-charhex.png\n" << std::endl;
for (auto c : "\a\t\\\"\n\x7f ABC") cpp_dump(c | cp::charhex());
std::clog << "\n// manipulator-addr.png\n" << std::endl;
int my_int = 15;
int *int_ptr = &my_int;
int **int_ptr_ptr = &int_ptr;
cpp_dump(int_ptr_ptr);
cpp_dump(int_ptr_ptr | cp::addr());
cpp_dump(int_ptr_ptr | cp::addr(1));
std::clog << std::endl;
}