My non-exhaustive implementation of std::vector in vector.h for learning's sake. Some std::algorithms threw at it in algorithms.cpp.
Almost no AI in vector.h (except small identified portions), while tests.cpp is fully AI-generated for the exercise's sake.
size_<=capacity_.v[i]foriin[0, size_-1] must be initialized (not just malloc-ed bytes but real T's constructed).v[i]foriin[size_,capacity_-1]must be not initialized, so freed or never initialized.data_==nullptr<-->capacity_=0- if
capacity_>0,data_is a pointer to a malloced piece ofcapacity_*sizeof(T)bytes.
One of the main challenge is that these rules should hold even in exception are thrown by the various ctor/dtor called in the vector's methods.
Both push back and emplace back can have an aliasing problem if the argument passed is a reference to an element of the vector an a reallocation is needed.