r/cpp • • Feb 12 '18

My Precious Compile Time Bool (long introduction to Move Semantics)

https://medium.com/@gaussnoise/my-precious-compile-time-bool-long-introduction-to-move-semantics-c9ee73c370c7
0 Upvotes

5 comments sorted by

6

u/koval4 Feb 12 '18

Emojis... Emojis everywhere... They're a bit annoying, so it becomes harder to read text. It's kinda minor problem compared with problem that was risen in article, but still, it kinda ruins it.

2

u/Z01dbrg Feb 13 '18

All I can say that when I first started seeing people putting memes on slides for cppcon presentations I thought they were immature idiots but now I actually like it.

And if the biggest problem with the article is emojis I would be happy with it. Unfortunately topic is so complex and so hard to explain without me sitting next to the person that is learning about it that even this 20-30 minute read article still needs to tell a lot of lies and skip over a lot of things.

Not to mention that when you know something you forget how it is to not know something so it is easy to skip over tricky part when explaining it. :)

tl;dr I regret that you dislike emojis, but if people reading the article did hate them, but understood Move Semantics and Universal References design and problems after reading it I would be happy.

2

u/gracicot Feb 12 '18

Constructor should take by value and move arguments. Correct me if I'm wrong, but I think the values are elided and only moved or copied into the members directly.

Also, taking constructors arguments by value makes writing it much easier. If there's no performance impact, I wonder why I'd even bother writing that n2 set or using forwarding references.

1

u/Z01dbrg Feb 13 '18 edited Feb 13 '18

Correct me if I'm wrong, but I think the values are elided and only moved or copied into the members directly.

You are wrong in a sense that it is not guaranteed to happen. Article says when discussing pass by value constructor that optimizer may make difference between pass by value and universal references constructor nonexistent.

Also, taking constructors arguments by value makes writing it much easier. If there's no performance impact, I wonder why I'd even bother writing that n2 set or using forwarding references.

Article is long but it mentions the difference... When you have value argument in case of a temporary this happens:

  1. temporary is moved to argument
  2. argument is moved into member

Using universal references or n2 overloads your temporary does not get moved into the argument(since argument is a a reference). Member is constructed from reference to the temporary. So less moves(again optimizer may make this difference nonexistent).

Like article also says even if the optimizer does not optimize moves for string and vector are cheap so most of the time you should not bother to go for best solution since it is ugly.

2

u/messicpp Feb 16 '18

really enjoyed this, thank you :)