@@ -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]);