std::vector::~vector(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::vector::~vector πŸ’–

okay bestie, welcome to the destructor page from the C++ Standard Libary manual, section 3 β€” and yes, "Libary" is literally how it's spelled in the header, iykyk, we are not coming for the typo, we are respecting the typo 🫢. This is the goodbye page. The "your lifetime is up, queen" page πŸ’…βœ¨


🌸 NAME 🌸

std::vector::~vector β€” it's giving destructor. Specifically, the destructor of std::vector. No cap.


✨ Synopsis ✨

~vector();  (constexpr since C++20)

so since C++20 this thing is constexpr, which is lowkey iconic of it 🌈.


πŸŽ€ Description πŸŽ€

okay so picture this: the vector has served its purpose, the main character energy has faded, and now it's time to clean up. Destructs the vector. That's the whole gig πŸ’€.

The destructors of the elements are called and the used storage is deallocated. Like, every single element gets its own little farewell moment, and then the memory the vector was using gets handed back. Very "everybody say bye" πŸ¦‹.

⚠️ but bestie, listen β€” if the elements are pointers, the pointed-to objects are not destroyed. the vector is not gonna chase down every pointer and delete what it points to for you. that is not the vibe. that is your job. don't @ me 😭

🧚 Complexity 🧚

Linear in the size of the vector. so it's O(n), it walks the whole squad, no shortcuts, no magic. big vector = longer goodbye. that's just how it is πŸ’œ.


and that's the page! source is http://cppreference.com, dated 2024.06.10, and the whole thing is std::vector::~vector(3) β€” destructor out, bestie, stay slay πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from