Create a "start" branch for a clean slate
dblume

dblume commited on 2024-03-21 08:54:55
Showing 2 changed files, with 8 additions and 197 deletions.


Well, sorta, only main is empty.
... ...
@@ -67,12 +67,11 @@ Use clang-format. Install the distro's version with:
67 67
 
68 68
     sudo apt install clang-format
69 69
 
70
-Or install a newer one (replace 17 with whatever's current now) with:
70
+Or install a newer one with:
71 71
 
72
-    wget https://apt.llvm.org/llvm.sh
73
-    chmod +x llvm.sh
74
-    sudo ./llvm.sh 17
75
-    sudo apt install clang-format-17
72
+    pipx install clang-format
73
+
74
+And move $HOME/.local/bin ahead of /usr/bin in your $PATH.
76 75
 
77 76
 Then, after making your edits, use the [vim integration](https://clang.llvm.org/docs/ClangFormat.html#vim-integration)
78 77
 or manually format in one of a couple of ways:
... ...
@@ -83,18 +82,18 @@ or manually format in one of a couple of ways:
83 82
 into the unstaged area.
84 83
 
85 84
 1. Stage the files you want to format.
86
-2. Run `git-clang-format --binary=clang-format-17 --style=file`, and it'll leave unstaged formatting changes.
85
+2. Run `git-clang-format --style=file`, and it'll leave unstaged formatting changes.
87 86
 3. Review with `git difftool` and accept the desired changes or unstage.
88 87
 
89 88
 ### Manually clang-format
90 89
 
91 90
     git status --porcelain | \
92 91
     awk 'match($1, "M|A") && match($2, "(c|h)(pp)?$"){print $2}' | \
93
-    xargs clang-format-17 -style=file -i
92
+    xargs clang-format -style=file -i
94 93
 
95 94
 Or, shorter but less comprehensive:
96 95
 
97
-    git ls-files -m | egrep ".(c|h)(pp)?$" | xargs clang-format-17 -style=file -i
96
+    git ls-files -m | egrep ".(c|h)(pp)?$" | xargs clang-format -style=file -i
98 97
 
99 98
 ## Current Features
100 99
 
... ...
@@ -6,199 +6,11 @@
6 6
 #include <memory>
7 7
 #include <complex>
8 8
 #include <cassert>
9
-#include "main_helper.hpp"
10
-#include "scoped_set_adder.hpp"
11
-#include "ui/widget.hpp"
12
-#include "../include/my_lib.hpp"
13
-#include "thread_with_lambda.hpp"
14
-#include "thread_manager.hpp"
15
-#include "deadlock/deadlock.hpp"
16
-#include "next_power_of_two.hpp"
17
-#include "unistd.h"
18
-#include "mmmm.hpp"
9
+#include <ctime>
19 10
 
20 11
 using namespace std;
21
-using namespace MY_LIB;
22
-
23
-int length_of_array;
24
-
25
-ostream& operator<<(ostream& ost, const int a[])
26
-{
27
-    // bad form: using global length_of_array
28
-    for (int i = 0; i < length_of_array; ++i) {
29
-        ost << a[i] << " ";
30
-    }
31
-    return ost;
32
-}
33
-
34
-// remove all instances of element n, return new length
35
-int remove_element(int a[], int n, int elem)
36
-{
37
-    int new_length = 0;
38
-    for (int i = 0; i < n; ++i) {
39
-        if (a[i] != elem) {
40
-            if (i != new_length) {
41
-                a[new_length] = a[i];
42
-            }
43
-            ++new_length;
44
-        }
45
-    }
46
-    return new_length;
47
-}
48
-
49
-// remove all duplicates of an element, return new length
50
-int remove_duplicates(int a[], int n)
51
-{
52
-    int last = 0;
53
-    for (int i = 1; i < n; ++i) {
54
-        if (a[last] != a[i]) {
55
-            ++last;
56
-            a[last] = a[i];
57
-        }
58
-    }
59
-    return last + 1;
60
-}
61
-
62
-void test_cpp14()
63
-{
64
-#if __cplusplus == 201402L
65
-    // Store a generalized lambda, that squares a number, in a variable
66
-    auto func = [](auto input) { return input * input; };
67
-
68
-    // square of an int
69
-    std::cout << func(10) << std::endl;
70
-
71
-    // square of a double
72
-    std::cout << func(2.345) << std::endl;
73
-
74
-    // square of a complex number
75
-    std::cout << func(std::complex<double>(3, -2)) << std::endl;
76
-#endif
77
-}
78
-
79
-struct Base
80
-{
81
-    Base(): x_(0) {}
82
-    virtual ~Base() {}
83
-    virtual void f() {}
84
-    int x_;
85
-};
86
-
87
-struct Derived : Base
88
-{
89
-    virtual void name() {}
90
-    public:
91
-    int g() { return 8; }
92
-};
93
-
94
-template <typename T>
95
-void writeNumber(int fd, T val, int base)
96
-{
97
-    if (val == 0) {
98
-        ssize_t bytes = write(fd, "0", 1);
99
-        (void)bytes;
100
-        return;
101
-    }
102
-    const int buflen = sizeof(val) * 8;
103
-    static char buf[buflen] = {0};
104
-    printf("* buf starts at %p and ends at %p and is %ld long\n", buf, &buf[(sizeof(val)*8)-1], sizeof(val)*8);
105
-
106
-    int i = 30;
107
-    for(; val && i ; --i, val /= base) {
108
-    //for(; val && i && (static_cast<int>(sizeof(val))*8 >= i); --i, val /= base)
109
-        printf("** i=%d, writing %c to %p\n", i, "0123456789abcdef"[val % base], &buf[i-1]);
110
-        buf[i-1] = "0123456789abcdef"[val % base];
111
-    }
112
-    printf("** i=%d writing %d bytes %p\n", i, buflen-i, &buf[i+1]);
113
-
114
-    ssize_t bytes = write(fd, &buf[i], buflen - i);
115
-    (void)bytes;
116
-}
117 12
 
118 13
 int main()
119 14
 {
120
-    unsigned long long v2 = 0xF102030405060708;
121
-    writeNumber(1, v2, 16);
122
-    cout << endl;
123
-    writeNumber(1, v2, 10);
124
-    cout << endl;
125
-    writeNumber(1, v2, 8);
126
-    writeNumber(1, v2, 2);
127
-    cout << endl << "DXB end!" << endl;
128
-
129
-    length_of_array = 6;
130
-    int a[6] = {10, 20, 20, 30, 40, 40};
131
-    int item_to_remove = 20;
132
-
133
-    // thread_with_lambda();
134
-
135
-    Base* pb = new Derived;
136
-    std::shared_ptr<Base> sp(pb);
137
-    cout << "pb is " << pb << endl;
138
-    cout << "sp is " << sp << endl;
139
-    Derived* pd = dynamic_cast<Derived*>(sp.get());
140
-    if (pd) {
141
-        cout << "pd exists " << endl;
142
-    } else {
143
-        cout << "pd is NULL " << endl;
144
-    }
145
-    cout << "pd is " << pd << endl;
146
-
147
-    cout << "Removing " << item_to_remove << endl;
148
-    length_of_array = remove_element(a, length_of_array, item_to_remove);
149
-    cout << "a became " << a << endl;
150
-
151
-    length_of_array = 6;
152
-    int b[6] = {10, 20, 20, 30, 40, 40};
153
-    length_of_array = remove_duplicates(b, length_of_array);
154
-    cout << "Removing duplicates yielded " << length_of_array << " items " << b
155
-         << endl;
156
-
157
-    main_helper_fn();
158
-    UI::widget_cb();
159
-    cout << "sizeof(int) is " << sizeof(int) << "." << endl;
160
-    my_lib_fn();
161
-    my_lib_fn(5);
162
-    my_lib_rect r(16, 9);
163
-    cout << "area of rect r is " << r.area() << "." << endl;
164
-    test_cpp14();
165
-
166
-    {
167
-        std::unique_ptr<int> up(new int());
168
-        scoped_set_adder set_adder("a set_adder object");
169
-        scoped_set_adder another_set_adder("and another set_adder");
170
-        cout << "unique_ptr " << (up ? "passes" : "fails") << " if." << endl;
171
-        delete up.release();
172
-        cout << "unique_ptr after release " << (up ? "passes" : "fails") << " if."
173
-             << endl;
174
-        cout << "unique_ptr.get() after release " << (up.get() ? "passes" : "fails")
175
-             << " if." << endl;
176
-        scoped_set_adder::dump();
177
-    }
178
-
179
-    { // Testing Herb Sutter's pImpl template
180
-#if __cplusplus == 201402L
181
-        std::unique_ptr<MyClass> my_class(std::make_unique<MyClass>());
182
-        my_class->f();
183
-#endif
184
-    }
185
-
186
-    // cout << "deadlock() returned " << deadlock() << endl;
187
-
188
-    for (unsigned i :
189
-         {0, 1, 2, 3, 4, 5, 6, 7, 31, 32, 33, 4003, 65535, 65536, 65537}) {
190
-        cout << "next_power_of_two(" << i
191
-             << ") = " << round_up_to_next_power_of_two(i) << endl;
192
-        assert(round_up_to_next_power_of_two(i)
193
-               == another_round_up_to_next_power_of_two(i));
194
-    }
195
-
196
-    int some_long_variable_name{0};
197
-    if (some_long_variable_name + some_long_variable_name + some_long_variable_name + some_long_variable_name + some_long_variable_name) {
198
-        cout << "yep" << endl;
199
-    }
200
-
201
-    //test_mmmm(); // uses stdin
202
-    cout << "Done." << endl;
203 15
     return 0;
204 16
 }
205 17