commit f55b327f0322fd148dd7b971bd6c3418067ec112
parent 958b27e616425a249b9a3a88c987906b040365e3
Author: Andrew Laack <andrew@laack.co>
Date: Sat, 22 Aug 2026 11:58:49 -0500
Started writing code to follow along with the modern c++ cookbook
Diffstat:
4 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/exploration/a.out b/exploration/a.out
Binary files differ.
diff --git a/exploration/iterator.cpp b/exploration/iterator.cpp
@@ -0,0 +1,18 @@
+#include <vector>
+#include <iostream>
+
+int main() {
+ std::vector<int> vec = {1,2,10,3};
+
+ for (int value : vec)
+ std::cout << value << std::endl;
+
+ // same thing, different syntax
+ for (auto it = vec.begin(); it != vec.end(); ++it)
+ std::cout << *it << std::endl;
+
+ // basically, use the first option for iteration without index
+ // if you need the index then use standard for loop, not range based for loop
+
+
+}
diff --git a/modern-cpp-cookbook/ch1/auto/map-iterator.cpp b/modern-cpp-cookbook/ch1/auto/map-iterator.cpp
@@ -0,0 +1,26 @@
+#include <map>
+#include <string>
+#include <iostream>
+
+int main() {
+
+ std::map<std::string,std::string> m;
+
+ m["1"] = "Andrew";
+ m["2"] = "Person";
+ m["3"] = "Human";
+
+ // this is much better than
+ std::cout << "Auto" << std::endl;
+ for (auto it = m.begin(); it != m.end(); ++it) {
+ std::cout << it->first << " " << it->second << std::endl;
+ }
+
+ std::cout << "Explicit" << std::endl;
+ for (std::map<std::string, std::string>::const_iterator it = m.begin(); it != m.end(); ++it) {
+ std::cout << it->first << " " << it->second << std::endl;
+ }
+
+ return 0;
+
+}
diff --git a/modern-cpp-cookbook/ch1/auto/specify-type.cpp b/modern-cpp-cookbook/ch1/auto/specify-type.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <typeinfo>
+#include <vector>
+
+// output:
+// St16initializer_listIiE
+// St6vectorIiSaIiEE
+
+int main(){
+ auto ls = {1,2,3};
+ std::cout << typeid(ls).name() << std::endl;
+
+ std::vector<int> ls1 = {1,2,3};
+ std::cout << typeid(ls1).name() << std::endl;
+}