I really appreciate the video, it was great. Thank you ! Alex from UPS.
Great video. Very clear thx
Your way of teaching is really great…The Best…Not only this video but all of your series is great…
"Fundamental Concepts in Programming Languages", I think this paper by Christopher Strachey is a gentle introduction to theoretical part of programming languages which helps to clarify all these C++ concepts. It also introduced the idea of lvalues and rvalues, ad-hoc and parametric polymorphism etc. I guess in 1967.
Good video, but the rule of three which you have explained at 17:50 is not correct. Before C++11 it was rule of three. With new standard rule of five was introduced. Generic definition would be: if you must define any of the special member functions you should probably define all of them.
Also there is also mistake at 19:26. Standard says that move constructor and move operator can be generated (but there are rules for that). Not all compilers have this feature. I think that the Visual Studio 2017 compiler will generate them but one of the previous versions (2013 or 2015) didn't generated them.
Your video is really music in my ear… Very well structured, I really enjoyed it.. Thx a lot and keep the good work….
Amazing teacher. Thanks a lot.
what is the rvalue reference used for ?
Minor quibble. Regarding the new in C++ 11 "initializer syntax available everywhere and is now preferred". Originally I just thought it was terrific that I didn't need to create an otherwise unnecessary array in order to initialize my vector and other such blemishes in C++ 98 being removed.
Then I thought "Great, now people won't keep confusing assignment with copy construction when they are sloppy or rushing, because we will always say
TYPE var { initial value } instead of: TYPE var = initial value
which sort of looks like an assignment but actually calls a constructor."
At about 3:18 or so, you use the old syntax of copy constructor which calls a copy constructor but looks kinda assignment-y. Have you fully switched over to using { } syntax when calling copy constructors? I still sometimes find myself writing calls to copy constructors like that, but most modern C++ videos seem to totally avoid it because of the historical ambiguity due to looking like an assignment. Or because they only learned C++ recently and that's the way they always did it. I know both work, but this is a modern C++ video, so I think this may be a relevant point.
Now back to your video.
Regarding lvalues and rvalues early in the video. I would completely avoid showing 1 + 1 = 2 for the following reason. We get bit by the meaning of "=" in C/C++/etc. etc. as the assignment operator which mathematicians like Wirth and Dijkstra always hated, because for 600 years "=" meant what we now use "==" for in these languages. If we were using a language that used ":=" for assignment it would be different, but we aren't.
Secondly, people need to get away from thinking of lvalues as things appearing on the left hand side of an assignment and rvalues as things appearing on the right hand side of an assignment, even me. It might be best to just say "we used to think of these as which side of an assignment they were on, but really what we mean is that an lvalue always has an address and an rvalue either has none at all because it is a pure temporary, or has one for just a moment but it is about to expire so we treat it as if it didn't….
I'm never crazy about having identical names for constructor parameters and members, and I have been looking for the best standard to adopt. I'm definitely not crazy about qualifying the member names with "this->" as I've seen in some videos, but calling the parameter, say, ii so the constructor initializer looks like i(ii) isn't really ideal to me either. However, the solution of using v both for the data member and the parameter indeed gets rather confusing right at the end of the video.
"This is my cousin Daryl, this is my other cousin Daryl." That worked fine on that show (whichever it was) but that was as a joke.
very good explanation
How to set Cursor like you (as Linux) on Visual Studio ?
You've done it again! Excellent video.
There is only one corner case I want to ask about that you didn't make crystal clear.
struct Structure { int i; }; Structure myStructure{45}; // same with Structure myStructure = Structure{45}; if the constructor is not marked explicit and here it's all good Structure&& rrStructure = std::move(myStructure); // oneproduct what is rrStructure here is it an lvalue or an xvalue?
The expression std::move(myStructure) yields an xvalue correct?, but it is said that "you can't move an lvalue". (of course in order to move you need move ctor or move assignment operators and they are implicitly generated in struct Structure in this case).
It is said that xvalues may or many not have an identity (ie. as you correctly pointed out an address, or a name). rrStructure has type rvalue reference. rrStructure has an identity.
2 Questions: 1. What about rrStructure's value category? That is what I want to know.
2. Is the std::move(myStructure) valid there? Iis myStructure left in a valid unspecified state after the std::move?
Thanks!
Good stuff!! But I could not understand why 2 move are required in last example,?
These videos are truly great! I just wish the font was slightly smaller so you didn't have to keep scrolling up and down over and over…
First, thank You. Could You tell what version of C++ is in this video?
Your C++ Videos are awesome. You should go on with em.
I'd love to know which options you have set in VisualAssistX 🙂
I clearly understood the concept of move semantics only in 30 minutes! Which I couldn't understand clearly for 1.5 hour…
So if I have a custom STL vector class with copy ctor, copy operator, move ctor and move operator, to be more save I should say vector(vector<T>&& src) { operator=(std::move(src)); } instead of vector(vector<T>&& src) { operator=(src); }
but it will not touch `vector<T>&& src` anywhere inside this ctor. Does it make any difference or it is just a dignified way?
Gr8 content 🙂
You confused const and rvalue. An l value can be on the left or right, and so can an rvalue.
I did the same program in VS2015 and if constructor and virtual destructor is defined then (move constructor ,move assignment operator, copy constructor and assignment operator are provided by compiler) . Program worked fine. ? if constructor ,virtual destructor ,copy constructor and assignment operator are defined then also (move constructor ,move assignment operator are provided by compiler) . Program worked fine.? But yes if we define move constructor ,move assignment operator then we have to manually define copy constructor and assignment operator.
Underated
Would you need to free resources of Foo f (if any) before assigning it to a new object using the Rvalue Assignment Constructor?
Consider the following:
Foo f;
{ f=Foo(5); };
f now stole the resources of Foo(5). But would this create a memory leak if f already had resources.
fantastic tutorials
Dude, you're freaking awesome. I hope you know that.
This has been so helpful, and you explain it all really well 🙂 Thanks!
Thanks for this – makes the whole thing so much clearer.
I really appreciate the video, it was great. Thank you !
Alex from UPS.
Great video. Very clear thx
Your way of teaching is really great…The Best…Not only this video but all of your series is great…
"Fundamental Concepts in Programming Languages", I think this paper by Christopher Strachey is a gentle introduction to theoretical part of programming languages which helps to clarify all these C++ concepts. It also introduced the idea of lvalues and rvalues, ad-hoc and parametric polymorphism etc. I guess in 1967.
Good video, but the rule of three which you have explained at 17:50 is not correct. Before C++11 it was rule of three. With new standard rule of five was introduced. Generic definition would be: if you must define any of the special member functions you should probably define all of them.
Also there is also mistake at 19:26. Standard says that move constructor and move operator can be generated (but there are rules for that). Not all compilers have this feature. I think that the Visual Studio 2017 compiler will generate them but one of the previous versions (2013 or 2015) didn't generated them.
Your video is really music in my ear… Very well structured, I really enjoyed it.. Thx a lot and keep the good work….
Amazing teacher. Thanks a lot.
what is the rvalue reference used for ?
Minor quibble. Regarding the new in C++ 11 "initializer syntax available everywhere and is now preferred". Originally I just thought it was terrific that I didn't need to create an otherwise unnecessary array in order to initialize my vector and other such blemishes in C++ 98 being removed.
Then I thought "Great, now people won't keep confusing assignment with copy construction when they are sloppy or rushing, because we will always say
TYPE var { initial value }
instead of:
TYPE var = initial value
which sort of looks like an assignment but actually calls a constructor."
At about 3:18 or so, you use the old syntax of copy constructor which calls a copy constructor but looks kinda assignment-y. Have you fully switched over to using { } syntax when calling copy constructors? I still sometimes find myself writing calls to copy constructors like that, but most modern C++ videos seem to totally avoid it because of the historical ambiguity due to looking like an assignment. Or because they only learned C++ recently and that's the way they always did it. I know both work, but this is a modern C++ video, so I think this may be a relevant point.
Now back to your video.
Regarding lvalues and rvalues early in the video. I would completely avoid showing 1 + 1 = 2 for the following reason. We get bit by the meaning of "=" in C/C++/etc. etc. as the assignment operator which mathematicians like Wirth and Dijkstra always hated, because for 600 years "=" meant what we now use "==" for in these languages. If we were using a language that used ":=" for assignment it would be different, but we aren't.
Secondly, people need to get away from thinking of lvalues as things appearing on the left hand side of an assignment and rvalues as things appearing on the right hand side of an assignment, even me. It might be best to just say "we used to think of these as which side of an assignment they were on, but really what we mean is that an lvalue always has an address and an rvalue either has none at all because it is a pure temporary, or has one for just a moment but it is about to expire so we treat it as if it didn't….
I'm never crazy about having identical names for constructor parameters and members, and I have been looking for the best standard to adopt. I'm definitely not crazy about qualifying the member names with "this->" as I've seen in some videos, but calling the parameter, say, ii so the constructor initializer looks like i(ii) isn't really ideal to me either. However, the solution of using v both for the data member and the parameter indeed gets rather confusing right at the end of the video.
"This is my cousin Daryl, this is my other cousin Daryl." That worked fine on that show (whichever it was) but that was as a joke.
very good explanation
How to set Cursor like you (as Linux) on Visual Studio ?
You've done it again! Excellent video.
There is only one corner case I want to ask about that you didn't make crystal clear.
struct Structure { int i; };
Structure myStructure{45}; // same with Structure myStructure = Structure{45}; if the constructor is not marked explicit and here it's all good
Structure&& rrStructure = std::move(myStructure); // oneproduct what is rrStructure here is it an lvalue or an xvalue?
The expression std::move(myStructure) yields an xvalue correct?, but it is said that "you can't move an lvalue". (of course in order to move you need move ctor or move assignment operators and they are implicitly generated in struct Structure in this case).
It is said that xvalues may or many not have an identity (ie. as you correctly pointed out an address, or a name).
rrStructure has type rvalue reference.
rrStructure has an identity.
2 Questions:
1. What about rrStructure's value category? That is what I want to know.
2. Is the std::move(myStructure) valid there? Iis myStructure left in a valid unspecified state after the std::move?
Thanks!
Good stuff!! But I could not understand why 2 move are required in last example,?
These videos are truly great! I just wish the font was slightly smaller so you didn't have to keep scrolling up and down over and over…
First, thank You. Could You tell what version of C++ is in this video?
Your C++ Videos are awesome. You should go on with em.
I'd love to know which options you have set in VisualAssistX 🙂
I clearly understood the concept of move semantics only in 30 minutes! Which I couldn't understand clearly for 1.5 hour…
So if I have a custom STL vector class with copy ctor, copy operator, move ctor and move operator, to be more save I should say
vector(vector<T>&& src) { operator=(std::move(src)); }
instead of
vector(vector<T>&& src) { operator=(src); }
but it will not touch `vector<T>&& src` anywhere inside this ctor.
Does it make any difference or it is just a dignified way?
Gr8 content 🙂
You confused const and rvalue. An l value can be on the left or right, and so can an rvalue.
I did the same program in VS2015 and if constructor and virtual destructor is defined then (move constructor ,move assignment operator, copy constructor and assignment operator are provided by compiler) . Program worked fine. ?
if constructor ,virtual destructor ,copy constructor and assignment operator are defined then also (move constructor ,move assignment operator are provided by compiler) . Program worked fine.?
But yes if we define move constructor ,move assignment operator then we have to manually define copy constructor and assignment operator.
Underated
Would you need to free resources of Foo f (if any) before assigning it to a new object using the Rvalue Assignment Constructor?
Consider the following:
Foo f;
{
f=Foo(5);
};
f now stole the resources of Foo(5). But would this create a memory leak if f already had resources.
fantastic tutorials
Dude, you're freaking awesome. I hope you know that.
This has been so helpful, and you explain it all really well 🙂
Thanks!
Thanks for this – makes the whole thing so much clearer.