+ 2
unique_ptr with vector resize
Hi As we know that vector resize itself on push_back operation when size is reached. This is the reason copy constructor is called when there is resize operation . This behaviour is observed in below code for vector<A> vecInput in attached code. https://code.sololearn.com/ca18A2a25a40/#cpp now, question is why we could not observe either copy or move constructor called with unique_ptr with vector?
2 Respuestas
+ 2
You don't observe any move operations because the instances themselves were constructed on the heap, after all. The move constructor of std::unique_ptr<> only has to move the pointer and the deleter it stores, not the entire instance its pointer refers to.
0
Yup... Got it.... Unique_ptr is storing address , not the object itself ... Thanks a lot