r/cpp • u/wineandcode • May 01 '22
Move semantics and rvalue references: Modern C++ fundamentals
This post covers move semantics, value categories, and rvalue references introduced in C++11
6
u/Sec360 May 01 '22
This was a really bad article. I’m sorry but I’m downvoting this.
5
3
u/BroVic May 02 '22
What's bad about it? Can you recommend reading on this topic, cos I'm really interested in deepening my understanding around this.
20
u/KuntaStillSingle May 01 '22
Thanks for sharing this Medium article OP, I love to read from Medium "Where good ideas find you." I also love such trending articles on Medium as "6 reasons not to move to Ireland." When I need something to keep me interested, I disable my adblock and visit Medium to see what the most current Medium articles are which my friends are raving about.
15
u/WrongAndBeligerent May 01 '22
14 comment karma, 7k post karma, totally organic
5
u/Nobody_1707 May 01 '22 edited May 01 '22
Wait, so you mean it wasn't scathing sarcasm? Oh, you're talking about OP not KuntaStillSingle's reply.
7
u/aninteger May 01 '22
Yes, Medium articles are exciting indeed. Who needs that pesky back button in your browser anyway. Certainly not me! There's nothing more exciting than going to a medium.com article and watching it redirect to itnext.io.
4
u/dontyougetsoupedyet May 01 '22
Oh no fuck that, all the gloves are coming off after they posted as a text post.
3
u/bentheone May 01 '22
I do move around things but never had to implement move semantics in a class... maybe I'm doing something wrong. It seems to work even with class with pointers members. My project does not leak memory... (it's a game engine, so it's rather obvious when it leaks). I also never lose track of ownership.
2
u/canadajones68 May 02 '22
Rarely do you need move semantics for something to work. If your class is simple, the compiler default is fine. If you keep track of resources well enough by yourself, you also don't need it. It's just a handy tool for enforcing semantic constraints with the compiler; it's not necessary to achieve Turing-completeness.
2
u/NotMyRealNameObv May 04 '22
Is it owning pointers, or non-owning pointers? I.e. have you implemented destructors where you
deleteordelete []anything? If so, you are never moving anything around if you have not defined move ctor/assign yourself, as the move ctor/assign is not generated for classes with user-defined destructors.If the pointers are non-owning, it's very rare that you need to define copy/move operations yourself. The only cases I can think of is
The pointer points to some other data in the same class.
The pointer is somehow tied to its parent, e.g. pointer to its parent.
10
u/foonathan May 01 '22
Please post it as a link and not as a text post in the future.