publiciop.blogg.se

Template vector
Template vector








template vector

Newcapacity=nearest_power_of_2(newcapacity) // Keep the capacity of the vector as a power of 2 to avoid space wastage.

template vector

Void reserve(size_t newcapacity) // Change the capacity of the vector to be at least equal to "newcapacity" Void resize(const size_t &newsize) // Change the size of the vector exactly to "newsize". Myvector& operator =(myvector other) // Assignment operator Std::copy(&other,&other+other.size(),vector_pointer) Myvector(const myvector& other):vector_pointer(NULL),vector_size(0),vector_capacity(0) // Copy Constructor Myvector():vector_pointer(NULL),vector_size(0),vector_capacity(0) // Default Constructor T* vector_pointer // A pointer pointing to the start of the dynamic array. Any suggestions related to my commenting style are also welcome! size_t nearest_power_of_2(size_t n) // Return the nearest( and strictly greater than ) number to "n" which is a power of 2. Please review it to see if it can be improved.

  • All the routines associate with std::vector with respect to performance and space-usage.
  • template vector

    I've been using this as a reference.Īlthough I've succeeded in implementing most of the interface (only the parts I use the most), I'm still uncertain whether: I am trying to implement a vector-like container of my own (just to gain a better understanding of how std::vector works under the hood).










    Template vector