summaryrefslogtreecommitdiff
path: root/9p32.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-10-16 22:50:50 +0200
committerOskar <[email protected]>2024-10-16 22:50:50 +0200
commitce6f87441ab2343f7730139f20d25b41e9dd6080 (patch)
tree431dd16b72c4ab3fa947efad172a1238e538eac9 /9p32.cpp
parent1462c1a161b3e986e066da92638fc3e9813498d4 (diff)
some exercises added here that aren't done, will do later
Diffstat (limited to '9p32.cpp')
-rw-r--r--9p32.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/9p32.cpp b/9p32.cpp
new file mode 100644
index 0000000..06ea9f1
--- /dev/null
+++ b/9p32.cpp
@@ -0,0 +1,31 @@
+#include <vector>
+#include <iostream>
+
+/*
+ *
+ * 9.32
+ *
+ * Seems very much illegal, at least when using g++. But when compiling with clang++ it seems like it just works... What?
+ *
+ * After breaking out gdb and debugging both the clang++ and g++ program it seems like both compilers do different things
+ * g++ increments the iterator, clang++ (maybe does?) does not increment the iterator.
+ */
+
+int main () {
+
+ std::vector<int> vi = {0,1,2,3,4,5,6,7,8,9};
+ auto iter = vi.begin();
+ while (iter != vi.end()) {
+ if (*iter % 2) {
+ iter = vi.insert(iter, *iter++);
+ iter += 2;
+ } else
+ iter = vi.erase(iter);
+ }
+
+ for(auto &a : vi) {
+ std::cout << a << std::endl;
+ }
+
+ return 0;
+}