lvalue, rvalue, lvalue references and an intro to rvalue references | Modern Cpp Series Ep. 31

  Рет қаралды 17,509

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 68
@Yuvaraj-pd6ng
@Yuvaraj-pd6ng 10 ай бұрын
this is the best c++ series this video was amazing
@MikeShah
@MikeShah 10 ай бұрын
Cheers, thank you for the kind words!
@RahulBochare-z5m
@RahulBochare-z5m Күн бұрын
great explanation ,Mike.Thanks
@MikeShah
@MikeShah Күн бұрын
Cheers!
@k0185123
@k0185123 11 ай бұрын
Wow. I really enjoy how you break down these subtle concepts step by step. I came here because sometimes I am not sure about if some of my functions can return reference. I was wondering if that is related to this lvalue issue. So I didn't expect I'd learn this interesting "rvalue_reference"! This is so useful! I think sometimes it can indeed save computational time. Thank you very much for your sharing. I really love how to put everything together in one screen and smoothly control those windows. Hopefully one day I can be as professional as you! Thank you again!
@MikeShah
@MikeShah 11 ай бұрын
Cheers, thanks for the kind words! As for returning a reference -- just be careful when returning references to stack allocated data (same as with a pointer) -- as it's not clear what value will be in memory :)
@k0185123
@k0185123 11 ай бұрын
@@MikeShah Got it! Thank you for the reminder :)
@dwolrdcojp
@dwolrdcojp 2 жыл бұрын
I appreciate the pop quizzes. Really improves the value of the lesson!
@MikeShah
@MikeShah 2 жыл бұрын
Thank you for the kind words! On lessons like this I like to throw those in to test folks understanding :)
@OzanCetinaslan
@OzanCetinaslan 6 ай бұрын
Hello Mike, you are a great teacher and lately I really enjoy your videos. Why I am watching I do not know maybe you explain really clean :) In this video I noticed a small issue at the beginning (4:30 ish) when you define Lval and Rval. You say Lval is on memory and Rval does not point to anything. I am not sure if this is really the case. If you think about how Bjarne define the object you understand what I mean. Object: a piece of memory, Variable: a named object. So, if you map this info to Lval and Rval I believe that you understand what I mean. For example, string str = string{"Mike"}. So, in here, str = variable, which is Lval, string{"Mike"} = object which is Rval and certainly points to some address, but no one really needs to know. I hope I am clear. Anyways Mike, you are great please keep up.
@MikeShah
@MikeShah 6 ай бұрын
Hmm, indeed there might be a more clear way to define rvalue -- the definitions in the link below provide a bit more strict definition. I think rvalues indeed have some location, but you cannot realistically take the address of (with &) of these values so that's the main idea :) learn.microsoft.com/en-us/cpp/cpp/lvalues-and-rvalues-visual-cpp?view=msvc-170
@mohsenzare2511
@mohsenzare2511 8 ай бұрын
I saw this video a while ago, and know I come back to watch that again! thank for your great video!
@MikeShah
@MikeShah 8 ай бұрын
Cheers! You are most welcome!
@mytech6779
@mytech6779 Жыл бұрын
Very clean, as a hobbiest I've been struggling with this for years. At first I was thinking Local and Reference because the contexts where I fiest heard the term was talking about passing function arguments and scope. Then Left and Right [but no, I thought, it couldn't really be that simple, sometimes an L seems to be on the right or they are standing alone], and the formal technical definitions are rather cumbersome parse. But this video clears up a lot, and your example also made me realize they could be thought of as Location/Locateable [ "Loadable" from memory?] and Register because the rvalues live in the cpu registers (Ignoring some details like instruction immediates and i/o reads which live elsewhere, though the registers still generally act as their gate keeper.), eg `(A+B)`, A nd B may be loadable from memory but the sum only exists in a register prior to assignment.
@MikeShah
@MikeShah Жыл бұрын
Cheers, glad to hear this helped!
@stupidteous
@stupidteous 3 ай бұрын
hobbyist*
@mytech6779
@mytech6779 3 ай бұрын
@@stupidteous male-donkey*
@Quancept
@Quancept Жыл бұрын
damn! just like that I understood l-values and r-values. I don't know how to thank you enough Mike :)
@MikeShah
@MikeShah Жыл бұрын
Cheers, happy to help!
@robertstrickland9722
@robertstrickland9722 2 жыл бұрын
I really enjoyed this explanation, even more than reading about it in the C++ Crash Course by No Starch Press. Good job.
@MikeShah
@MikeShah 2 жыл бұрын
Thank you for the kind words!
@muhammedusman7269
@muhammedusman7269 11 ай бұрын
all videos are great and excellent. Thanks
@MikeShah
@MikeShah 11 ай бұрын
Cheers!
@piotrlezanski5156
@piotrlezanski5156 10 ай бұрын
You are great! Thanks
@MikeShah
@MikeShah 10 ай бұрын
Thank you for the kind words 🙏
@FadiEID-s3g
@FadiEID-s3g 4 ай бұрын
42. There is something to that number. Perhaps the piscine?
@MikeShah
@MikeShah 4 ай бұрын
From Douglas Adam's book -- Hitchhiker's Guide to the Galaxy :)
@lucasnicosia3536
@lucasnicosia3536 3 ай бұрын
Il a pas la ref dans la ref 😅
@MindHaunter
@MindHaunter 3 ай бұрын
Between `std::string s3 = s1+s2;` and `std::string&& s3 = s1+s2;`, the latter is indeed slower (for s2 around 4000 characters), especially with -O3 or -O2 optimization. I am sure there are use cases for rvalue ref (and you will teach us in the next videos), but this simple example is probably not one of them. As always, thank you for detailed explanations. Coming from python and R, I cannot imagine how terribly it'd have been if I just wanted to follow cppref or learncpp.
@MikeShah
@MikeShah 3 ай бұрын
Cheers! I'll need to think about what exactly is going on when we do std::string&& s3 = s1+s2. To me we're doing all of the construction, and then we move s1 and s2 (or otherwise extend their lifetime). We'll have to be careful otherwise as we can pass s3 into a function only once. I'll talk about this in a future video when I also cover things like perfect forwarding :)
@TheIntervurt
@TheIntervurt 2 жыл бұрын
Did you mean to say copy assignment operator at 24:22 ? Thank you for these videos, you take the time to present several examples and explain what is going on behind the scenes which I think is often overlooked in many resources teaching C++
@MikeShah
@MikeShah 2 жыл бұрын
I meant to say copy constructor. Copy constructor is called when the object is first being initialized from a previously created object. Looks like I mixed my words a bit. :)
@muhammadharris4470
@muhammadharris4470 2 жыл бұрын
Thanks mike for teaching this super important topic for extreme simplicity. really love your teaching style 👍
@MikeShah
@MikeShah 2 жыл бұрын
Cheers thank you for the kind words!
@IsaacC20
@IsaacC20 6 ай бұрын
@28:44 How do you use declspec to check value category of expressions?
@MikeShah
@MikeShah 6 ай бұрын
There's a trick you can use with templates to get the decltype of a type. See stackoverflow.com/questions/16637945/empirically-determine-value-category-of-c11-expression
@guilherme5094
@guilherme5094 3 ай бұрын
👍Thanks again!
@dhanushs1802
@dhanushs1802 2 жыл бұрын
Very well explained as always. Thank you.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers thank you for the kind words!
@muhammedhasankayapnar9495
@muhammedhasankayapnar9495 Жыл бұрын
Hi Mike, thank you for this wonderful lecture. As far as I understand, rightvalue references can be used for large data processing for the purpose of preventing stackoverflow. How do we see the s3? since rvalue_references do not have any addresses/memory location ? Is that magic :) ?
@MikeShah
@MikeShah Жыл бұрын
Thank you for the kind words. Can you provide a timestamp for the example?
@visitor_t-w3p
@visitor_t-w3p Жыл бұрын
Thank you so much I enjoyed a lot
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@kamilziemian995
@kamilziemian995 11 ай бұрын
Very nice video.
@MikeShah
@MikeShah 11 ай бұрын
Cheers!
@MrTNVolsFan
@MrTNVolsFan Жыл бұрын
I get the error: error C2440: 'initializing': cannot convert from 'std::basic_string' to 'std::string &&'
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
I forgot to thank you for your hard work and sharing your knowledge. Do you have a roadmap to advise for one who wnat to be c++ developper in the embedded system and game developpment. i have been scoring the internet looking for books which teach c++ with under the hood concepts and explanations. Please advise for books. Yours sincerely
@MikeShah
@MikeShah 2 жыл бұрын
You are most welcome! I'd recommend "C++ for game programmers" second edition, "C++ API Design" , then any "Building games in C++" style book. Then follow up with Jason Gregory's "Game Engine Architecture" after you have built a few small games. "Computer Systems a programmers perspective" also is a book of high value. That's a good starting list, perhaps I'll do a video on some book recommendations :)
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
@@MikeShah Thank you Mike for your advise. I was asking about books which can teach solid background of c++ in general. I loved your tutorials becuase the pictorial explaiations make it relatively easy to follow, so i have been willing to get a book with such details of explanation. Your recommended list mostly focus on game programming which i would like to do as a hobby to apply and learn c++. My study field is mechatronics. Which is why i asked for books in embedded system domain(Robotics, automation). As you said a video would be greatly appreciated.
@MikeShah
@MikeShah 2 жыл бұрын
@@blaisofotso3439 You are most welcome! I will add the video idea to the wish list, as I have a series of education content I would like to make advising some books I have enjoyed :) Your field of study is a good one!
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
@@MikeShah Thank you .
@joymakerRC
@joymakerRC Жыл бұрын
needed this one bro
@joymakerRC
@joymakerRC Жыл бұрын
i had come across the exact issue earlier this summer when attempting my mode manager class, couldnt figure out why my funtions wouldnt compile to test correctly when i just entered a hard number. I didnt know all this at the time and just assumed i had to create variables all the time for parameters. I had just recent read In "deciphering OOP in C++" when writing a test driver for a class that this can occur.
@MikeShah
@MikeShah Жыл бұрын
Cheers
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
Hallo Mike I have tried adding two integers and assigned the result to an Rvalue reference and it has worked. my question to you is : we never wrote a move assignment operator, is the compiler doing it behind our back?
@MikeShah
@MikeShah 2 жыл бұрын
For the primitive types, we need not have these implemented for rvalue references (i..e int&& rv_ref = 42;). It' sort of how we never have constructors for 'int' in C++ for example. We'd call 'int' 'long' 'char' etc. trivial types in C++.
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
@@MikeShah I had that feeling. I was surprised that we perform the move assignement without implementing it. Then i thought that the compiler might have done it as it would when making copy without pointer as data member. In all thank you for your comment about the reason why, it helps with understanding the basics. "There is no rules without exception" . "l exception qui confirme la règle"
@arjunkandaswamy1532
@arjunkandaswamy1532 Жыл бұрын
&& was great
@ARANDOMOPENAIUSER
@ARANDOMOPENAIUSER Жыл бұрын
24:25
@MrTNVolsFan
@MrTNVolsFan Жыл бұрын
Concerning the std::string&& s3 = s1+s2, it doesn't work in C++20. Is it deprecated in the modern language?
@MikeShah
@MikeShah Жыл бұрын
Not sure--what message are you getting with what compiler?
@VoidloniXaarii
@VoidloniXaarii Жыл бұрын
Thanks so much
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@bobweiram6321
@bobweiram6321 Жыл бұрын
What does the name Shah mean? Does it mean king in Parsi?
@MikeShah
@MikeShah Жыл бұрын
Depends on the language, but yes, King is one meaning 🙂
@JamalOmar-p5c
@JamalOmar-p5c 20 күн бұрын
Great lessons, shame about all the "go ahead" which is superfluous and irritating. I went ahead and turned it off
@damondouglas
@damondouglas 2 жыл бұрын
It finally started to click for me at this place kzbin.info/www/bejne/pn6meYqKrK6KpNU
@MikeShah
@MikeShah 2 жыл бұрын
It's a bit obscure to think of variables as something that stores information and also something with a 'value category' or 'identity' (being lvalue, rvalue, etc.). :)
Introduction to std::move in C++ | Modern Cpp Series Ep. 32
10:03
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
lvalues and rvalues in C++
14:13
The Cherno
Рет қаралды 332 М.
C++ 27. move-семантика, move-конструкторы
1:21:15
Лекторий ФПМИ
Рет қаралды 11 М.
Introduction to constexpr | Modern Cpp Series Ep. 86
10:56
Mike Shah
Рет қаралды 13 М.
The Only Unbreakable Law
53:25
Molly Rocket
Рет қаралды 358 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН