21
Dec
2021

Move Semantics in the std::remove and std::remove_if

std::remove and std::remove_if functions are Inside the C++ algorithm library. We shouldn’t forget these functions names contain “move” These functions are valid only for more assignable objects. Remove functions returns the end of the iterator for the new range. These functions only remove the elements by shifting. It means, the remove() functions don’t erase the...
Read More
16
Dec
2021

Shallow Copy & Deep Copy

“It is only shallow people who do not judge by appearances. The true mystery of the world is the visible, not the invisible….” ― Oscar Wilde, The Picture of Dorian Gray Most of the times something for which is learned deeply is profitable. But always, something for which is performed shallowly is safe. In this blog, we...
Read More
17
Oct
2021

Smart Pointers (5/6): std::weak_ptr

Before talking about the std::weak_ptr, it would be nice to talk about weak and strong type pointers. As an example of a strong type pointer, std::shared_ptr holds the owner and increases its reference counter. It means every strong type pointer keeps alive its resource individually. This feature causes a big problem sometimes. We will talk...
Read More
14
Oct
2021

Smart Pointers (3/6): std::shared_ptr

Automatic memory management alias garbage collector provides release of memory which was allocated by the program, but, then, is no longer referenced. C++ has no explicit garbage collector mechanism. Quotation from Bjarne Strousb: “I don’t like garbage. I don’t like littering. My ideal is to eliminate the need for a garbage colletor by not producting...
Read More
14
Oct
2021

Smart Pointers (1/6): std::unique_ptr

If you don’t want to change your raw pointer habits and want to get coverage of smart pointers; then the standard libraries’ unique pointer is the most convenient choice! Std::unique_ptr exclusively manages the resource during its lifetime. Here are some features of the unique pointers with proofs and codes! 1. Std::unique_ptrs are the same size...
Read More
14
Oct
2021

Smart Pointers (0/6)

Before talking about smart pointers, I would like to talk briefly about non-smart pointers also known as raw pointers. If we create a primitive type such as “int” or an object on the heap, the memory responsibilities belong to us. Ignoring the memory control mechanism can cause some problems such as having a dangling pointer,...
Read More