0

enter image description hereI am learning C++ and I came across move semantics. However I am unable to understand as to what is happening when we are try to add a new element to a vector that is full. How is move different from copying. We would any how have to allocate new memory for e.g. twice the size of the previous vector. What will std::move() do under the hood is what I can't visualize and understand. Can somebody point to a resource that makes it clear. I have tried a couple of blogs but all I get is that std::move() is just type casting lvale ref to rvalue ref, it is not moving anything. So what is the advantage? Specifically, I don't understand the section of code circled in red.

The book I am following is C++ primer (5th edition).

Thank you

Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79
Ajx
  • 53
  • 1
  • 5
  • Which specific part of your C++ textbook's chapter on move semantics is unclear to you? Feel free to cite a brief excerpt and explain the confusion. Unfortunately, Stackoverflow is not a replacement for a textbook, and it wouldn't make much sense to copy/paste entire chapters that fully explain move semantics, as answers here. So, for large topics like that we refer everyone to their textbooks for more information. – Sam Varshavchik Nov 01 '21 at 11:04
  • It might help you : https://stackoverflow.com/questions/3413470/what-is-stdmove-and-when-should-it-be-used – Mojtaba Valizadeh Nov 01 '21 at 11:21

0 Answers0