Browse Source

more comments

Kajetan Johannes Hammerle 3 years ago
parent
commit
31ca2871b8
1 changed files with 13 additions and 3 deletions
  1. 13 3
      Main.cpp

+ 13 - 3
Main.cpp

@@ -2,9 +2,15 @@
 #include <iostream>
 #include <vector>
 
-// this struct is used in the automated tests at the end of the file
-// it counts all instances with different numbers to ensure each object is
-// constructed and destructed the same amount
+// All implementations in this class use ints insteads of size_t because size_t
+// is interely slow compared to ints. C++20 also adds new methods to call for
+// signed container sizes. Several online resources also suggest to use unsigned
+// types mostly for bit operations and nothign else.
+
+// This struct is used in the automated tests at the end of the file.
+// It counts all instances with different numbers to ensure each object is
+// constructed and destructed the same amount of times.
+// A also has a non trivial constructor to test the vector
 struct A {
     static int instances;
     int a;
@@ -214,6 +220,10 @@ public:
         data[elements].~T();
     }
 
+    int length() const {
+        return capacity;
+    }
+
 private:
     static T* allocate(int length) {
         return reinterpret_cast<T*>(new char[sizeof(T) * length]);