An Effective C++11/14 Sampler

aghuttun · 75K views · 2013 · 1:15:45

Open on YouTube

C, C++, Rust, Go & systems languagesProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining or learning std::move and std::forward behavior, and when discussing C++11 library details like std::string copy semantics.

Recommended by 1 people across 1 different months, 2014 to 2016.

What it is

Scott Meyers' Going Native 2013 talk previewing items from his planned book on effective C++11/14. It covers topics such as std::move, std::forward and universal references, with code examples, and is presented live at the conference.

What people said

Recommends vishal · 2015-10 · Stack Overflow · on “move vs forward on universal references”

Understand two thing: 1) 'move' does not guarantee to move 2) 'forward' does not forward a code. move is an unconditional operator forward is a conditional operator. Confused?? please watch this video: [this video]

Cites user2485710 · 2014-09 · Stack Overflow · on “Is std::string still copy-on-write with C++11?”

@bames53 there is a talk where this is mentioned [this video] but there is another comment that points to something not being correctly implemented in the way `std::string` is being copied or moved, the comment dated `12 Jun 2014 7:11 PM` ( sorry no permalink from that page apparently ) here [LINK] and there is still no clear answer to that question .

Cites orenshochat · 2016-07 · Stack Overflow · on “std::forward Visual Studio 13 doesn't behave like I expect”

I'm trying to learn some basic C++ 11, using Scott Meyers lecture on youtube called "An Effective C++11/14 Sampler" [this video] Using his sample code for std::forward (min 19 in the lecture) I wrote the following code to understand the effect of std::forward #include "stdafx.h" #include <string> #include <utility> class A { public: void Foo(std::string&& s) { std::string s2 = std::forward<std::string>(s); } }; int _tmain(int argc, _TCHAR* argv[]) { A a; std::string s3 = "Hello World"; a.Foo(s3); a.Foo("Hello World"); return 0; } Surprisingly it doesn't compile, a.Foo(s3) can't implicitly cast from lvalue to rvalue. So I changed a.Foo(s3); to a.Foo(std::move(s3)); Now it compiles. However on both