CppCon 2019: Klaus Iglberger “Back to Basics: Move Semantics (part 2 of 2)”

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so welcome ladies and gentlemen welcome to back to basics smooth semantics part 2 perhaps a slightly more interesting part because this is now going more into the details of move semantics so for those who have not been here in the first part my name is Chloe burger - a surplus of trainer since 2016 I'm also senior soft engineer it's seaman's and I might know one of my works I'm the author of the place he passed pass math library also additionally I am co-organizer one of the four organizes of the Munich C++ user group also sometimes present Etsy places conferences we are now in part two in this part I will be dealing with forwarding references meaning we will talk about perfect forwarding pairs of perfect for wedding and overloading with for wedding references and I will also show a couple of common pitfalls that hopefully afterwards you will avoid this part is going to be a little more interactive than the first part again please if you know the answer because you are a very experienced C++ guy allow the audience the rest of the people to think about this for let's say three seconds and then you can give it away this I think this is just fair this is okay if you have a question in between I believe we have enough time for that please go up to the mic now it's been moved forward the acoustics should be a little better now so for the recording this is perfect please use the mic alright this is the feeling that you still have from the first part yes I have mastered move semantics it's not that difficult why are people complaining why is this something that people argue is so difficult one of the most difficult features well I did not mention another feature I'm not talking about forwarding references these two fellows here the red ones T ref ref and also this r2 ref ref this looks like our value references to some extended purposes you feels like an R value reference if you look at it but unfortunately it's not this is a special kind of reference and immediately this good feeling that you have before is gone oh my what have they done okay so at first give me a chance to explain what forwarding references are because they indeed are special a forwarding reference represents an l-value reference if you pass it in ll value and as a reminder and L value is something with a name and a forwarding reference represents an r-value reference if you give it an R value so meaning it adapts it is whatever you initialize it with and an R value reference is in fact forwarding reference if it involves type deduction and this is exactly these two thinks so either function template or order and if it appears in exactly this form so only if you encounter and in quotation marks are value reference in this form then it happens to be the special kind of reference and r-value reference now let me show you why they are special why they behave differently let's say that I indeed have a function camp template called foo and food takes an T ref ref argument well remember this is one of the forms I showed before and just to prove that something happens I have added some output now in the main function I have a widget this is an LL value it has a name and I pass it to foo it should not work from all I've said so far this should not compile because an L value should not bind to novel reference this would be bad we would move from the L value the elavil can still be used I have a name this would be bad but it does compile and it prints so this is the signature it does compile and it prints fruity ref ref so I've called the function surprisingly now what happens why does this work well in argument deduction this team is Fornell value deduced to be widget ref I can I don't unfortunate don't have time to go into details why this is now made of widget ref there is a one-hour talk by Scott Myers from 2014 that goes in a lot of detail about type deduction but believe me T is the juice to be widget ref but there is another set of references so I have widget ref space ref ref the space actually makes it something different you are actually not allowed to write this kind of code you cannot make a reference to reference this is illegal but the the compiler cannot can come up with this new entire deduction now I have two references an l-value reference and an r-value reference we must do something and it's something called reference collapsing if indeed during template argument deduction I have a reference to a reference then I simply remove one of them and rule is as soon as I have one L value reference in this mix the result is an L value reference only and exclusively if I have a ref ref ref ref in the end I have a ref ref and so now you understand why there's so many dog jokes okay in this case I end up with a single L value reference that's the deduction rule or the reference collapsing rule and so finally this is the function that we would have a function the full function that takes an L value because it's an L value reference and so it compiles I can pass W to the function it's an L value this fits perfectly I know this is a little frightening but what about our values let's pass an R value let's create a widget without a name this is an R value in this particular case okay again it calls the function it prints foo so also this works and it works because now this T is deduced to be simply widget okay again don't ask me about the details the result is widget ref ref and this is exactly the kind of argument that the parameter that I need to pass an r-value widget widget refer it fits perfectly oh my I know what you're thinking right now what okay take a deep breath yeah so perhaps this helps a little bit okay relax your mind a little bit of course there is a very very good reason why they added this to C++ and now I have to some extent blame how I didn't he came up with this because there was indeed a problem was truly and soft in C++ 98 and oh three so prior C++ 11 and this problem is perfect for wording if you want to write a function that is merely forwarding its arguments to some other function then you have exactly this situation so a good example is the simplest is 14 make unique makes uni tasks is just to forward the arguments that give to it to the constructor of a T and so whatever T I have I just want to forward the arguments now how do I do that this interestingly was a problem totally unsolved prior to C plus 11 of pre C plus 11 because there was not not a good general solution the first solution that we would have is to pass by value this works pretty often it might not work for types that are not copyable though this is alimentation and of course this creates overhead imagine that i want to pass a string a vector something big I do not want to create an extra copy this is not perfect forwarding this would be kind of a forwarding but not perfect forwarding so for instance yeah imps would be fine widgets you saw this contained string unit pointer this would be expensive we could pass by reference non constants that surprisingly works for console village too so our could also have a Const but this year for instance this would not work I could not pass an r-value because in our Valley does not bind to an l-value reference to none Const it should not this was something at from the so in before the standard was forbidden this also causes problems a lot so this would not compile it's not perfect forwarding either called group of arguments would be impossible and the third option 1/2 is reference to Const of course the usual default this is actually not so bad it works for a lot of things but it is again one limitation let's say for instance that I have a class example that takes an int ref and I want to create an example so it has constructed they take an interest and I want you create an example by means of make unique I want to pass an int + int ref I cannot because I have already added the Const in the function and a chemical cannot get rid of it anymore so also this would not compile meaning there was no perfect solution no general solution all the options I have have some limitation we were basically bound to have special-purpose solutions this is exactly what forwarding references supposed to solve and this is exactly where they get their name from this allows you to pass anything this X this except L values is ax accepts our values cons values none can spell is volatile non-volatile anything that you could possibly have perfect this is the right kind of reference this is by the way why Scott Myers initially call these universal reference it is kind of universal it accepts anything and it can be anything now it's just a small additional problem that you now have and this is what you've seen before this may be in our value okay I can pass null value to this function but just because in this function it has a name it becomes an L value again and now as an elderly if it forwarded in this form I basically remove the opportunity to move this into T so it's again not perfect this is a limitation using move at this point of course again would be big mistake if I pass an L value I would unconditionally move and this would of course destroy me l valid it might still be used in the calling scope that so I need something different instead of an unconditional move I need a conditional move a move that only moves if it is indeed an R value and this is what was introduced okay the animation litoris was in what was introduced by means of standard forward let's say little brother of standard move standard forward is a conditional move for the reason it looks similar yet different to just an ad move it doesn't that static cast also but directly cast 2d ref ref there's no remove reference whatever it looks a little simpler I will a little later tell you about the the implementation details of forward how it works etc for now let's just say we use this forward we use it a little different though than move we additionally passed the type the value arc does not help me it's always an L value but the type gives it away if the type shows me this is nel value I basically cast to an L value reference again if the type shows me this is an R value I cast to an R value reference so stood forward is the conditionally moved and ended here and now it's certainly perfect whatever you pass to this function it will perfectly with exactly this right type with exactly the same properties forwarded to the function so in this case the constructor of T perfect now make unique is of course not quite complete in in real life it has uses forwarding references so now I can pass an arbitrary number of elements and all of them are forwarding references of course this is the final make unique but it works exactly as before I forward every single argument in exactly the same way perfect now let's take it should look at how center-forward works it is not something particularly difficult but again it is relying on reference collapsing so this is how we used it we passed the type arcs so this is the forward function again let's first of all assume that I pass an l-value if a pass and which it again my toy example and it an l-value widget then T would as before become a widget ref exactly the same thing as before in all the places where had T suddenly have a widget ref and now the same rules as before apply widget ref ref ref becomes in these two ka places a widget ref and it's remove reference T of widget ref will simply be resolved to widget and so ultimately this is the forward function that would be instantiated okay I take a widget an l-value and I've cast to an l-value reference so if you pass in an L value you get back in L value reference however if I pass it in our value then just as before we would deduce widget just widget so widget ref ref perfect I do not have to do reference collapsing here and remove reference T would resolve to widget so again I get in a valley widget but every turn in this case widget ref ref I statically cast to widget refresh and so if you pass an R value you will get back in our Val reference you cast to the right type again so it's not a big mr. e it's not a lot of magic it just uses the rules that we've seen before in a very nice way and so the mechanics off stood forward by the way going back to do the initial signature this is how it looks like and yes it is different to what move looks like so I showed you move before and now for the first time we can perfectly analyze move move indeed takes a forwarding reference I didn't mention this before part of the second part but yes this T ref ref here is in fact a falling reference this is why move just takes anything just give me an L value or an R value constant on console I don't care I will cast it into a are value reference all right this sounds like a pretty good idea so far Oh foreign references but take anything oh cool absolutely nice this is exactly what it's looking for unfortunately there is indeed a couple of perils that you should be at least aware of and as an example I now introduce a construct here to simplify things person a person has a constructor that takes a name by string this is a reasonable choice probably so I can name a person by string but there's so many more kinds of strings so we might consider string view and of course he said string literals cue string and okay so there's many kinds of strings you might have the idea that disable at work you introduce another constructor that takes a forwarding reference any kind of string this sounds pretty nice all right let's use this let's create a person and decided to create a piano on my own everybody needs a piano which constructor is used to create my piano correct the second one you might think but this is a string no it's not a string this is AC string riddle of type char seven yeah I can count it six characters but there's also the null terminating character and this fits best to the reference the T reference well it could be anything so it takes reference to HR seven and we're done we do not have at this point to create a string first but this is exactly what we wanted cool not bad okay I want a second person what person do I create I think you only needs herb yes everybody needs a herb too so I create a herb and I create a string first so string named herb and I pass the string now which constructors used to create herb okay I hear a couple of one this is exactly what we expect this is very natural I have a string it's of course how why should it be different of course it goes to the first function but no it does not it's cause the second function and slowly but steadily feel oh this is unexpected this is probably something that you later have to think through again so why does it call the second function well it calls the second function just because the argument the name is not constant this is the only difference yet the only detail that makes it call the second function the second function is instantiated in exactly the same form I explained before is to take a string ref it's an l-value string reference collapsing etc string ref now I have two functions after this template in sensation they can choose construct the one it takes a con string and this newly accentuated second function taking string ref none Const which one is better oh yeah the second one just because it's not constants you can easily prove this at accounts to the name it will call the first firm that was unexpected pretty unexpected but this is not even the worst thing okay we now do something that we probably shouldn't do but we do another less if if you don't tell I perfectly fine with it we are not cloning one of these two guys and I decided to clone a PNM everybody needs to be on a'right so I'm now creating yharnam again as a copy I pass p1 s the argument now watch happens what do you think what do we expect I actually hope that you're thinking of course we do a copy everybody copies superior and for that purpose of course we have a copy constructor no it does not call the copy constructor unfortunately it calls constructor two again why well same argument bernie is not Const Bjorn is a free man and for that reason again the second function is just a tiny bit better the second constructor would take a person ref the copy constructor on the other hand takes a Const person ref okay I cannot exactly I can imagine what you're thinking right now Oh what okay again Keep Calm this is perhaps this helps yeah so the problem is of course that we have to remember that this is indeed special and the problem is primarily overloading on forwarding references in order to give you an idea now let's practice this a little bit so now it becomes a limo and either interactive on the right I have a function G that does a couple of things now in this example it creates a widget W and passes this w to F and believe it or not I have six F functions one two three four five six all of them can perfectly live in harmony because all of them just take references but all possible kinds of references function one takes a nun constants so reference L Valley reference to nun Const function two takes an l-value reference to Const function three takes an R value reference function for it takes although this is probably not something that you've seen a wild and arveleï reference to Const function five takes a falling reference hopefully you see this by now and function six takes a constant here F ref which makes it a an R value reference again so this is not a forwarding reference this is just a yeah an R value reference to constic in so given the code on the right I have an L value it has a name and I pass it to F which of these six functions is chosen as the primary choice in other words what is the best match okay I hear a couple of answers and see a couple of answers this calls function 1 some people expected function 5 well actually this is really really close function 5 is considered of course as well it is instantiated and the compiler comes up with a signature so function 5 becomes F of widget ref exactly the same signatures function 1 can also happen during template instantiation now we have two functions they take a widget ref luckily there's a rule in C++ that says if a template is instantiated it becomes exactly the same signature is a non template function the non template is preferred and for that reason function one is the better match although strictly speaking both are equally we'll managed now let's assume that function 1 does not exist what would be the second choice this so ignore function 1 would be that what would be the best choice of the remaining 5 correct function 5 because it is the same signature and now that the function 1 doesn't exist anymore this is the best match there's a third possibility the third best choice which of these functions is also an option but was not chosen yet because of the other two correct function to a Narvel is a an l-value can of course be passed to and will reference to Const this works the other three functions are not an optional and have an L value does not bind to normally reference this would be bad then something would be moved and again I would have a pretty big problem this is the only choices all right let's make the code on the right hand side create and cons widget a console really and let's again think which function is caught so it's the same functions on the left all right I see a couple of two and you're correct function two is now again the best match but again there is one function it is a very very tough competitor and it only loses Bigfoot because its template that is function v function v is again the second best match so try it it is indeed function v why not six so function six is not an option because it takes in our value reference it is an r-value reference I can pass in cons elavil to forwarding reference but I cannot pass an elderly in any state consonant cons to an r-value reference never works this is why function six is indeed not an option perhaps to some extent this proofs is an r-value reference this is the only choices are half in this case function one is not an option because of the constant I can remove constantly others are again r-value references the fun continues now I have our values on the right hand side so the function that creates our values assuming that I call F with an R value which function would be the best match okay I should be specific and none can starve le of course okay if starting to pick up a pattern here this is not bad function three function three is the best choice because it's again a perfect match however yet again function five is a very tough competitor the compiler will come up with a signature widget ref ref it is only loosing again because it's a template if function three does not exist this function would be called yet again and you start to get the feeling if there is if there's no other function it it's a perfect match I so called identity match then this tiny little black hole called forwarding reference takes it all not in this case I have a third choice what would be assuming that these two do not exist what would be the third choice function for is correct I have an r-value an RV le wants to bind to novel reference and so this function is a little better function six is a template and so again function for is preferred and function six would in this situation be the second choice but if you thought to correct it is a choice but however this is the fallback this is the fallback that has ever has always existed since the very beginning our values bind to El Valle reference to Const so if you do not use our value references at all so if function three to six do not exist then function two is the common fallback this by the way it's also the reason why if you don't use move it still works if you can r-value it would simply call the copy constructor of something it will create a copy okay there's of course one one possibility left I do not think that you see this a lot in in in wild I now create a Const R value which function is now the best match you know what do you think but I like to play it till the end okay function for perfect so if you thought about this right away I think you got it what would be the second choice okay actually are correct it's six okay you avoided my trap this is the first case in the only case where it does not call five this time function six is a little bit better because of the counts this takes cars are really references the function five however would indeed match exactly the signature function six but because the other one is Const meaning a little more special function six is called in function five is only the third choice and also here I can choose function two as the final fourth choice function one and function function one is not an option because it's an L you reference and functions three is normal reference of course but it hasn't any Const all right now I think you got it still it is a pretty complicated so overloading with forwarding references is something that is probably best avoided make unique a single function it is somewhere this is where it is working best so personal refer my personal advice if you indeed what to solve this forwarding this perfect folding problem useful reading references because there's nothing better this is exactly what it does well do not just use it randomly so if you use a forwarding reference then use it for a specific reason ya know what you're doing and I basically just give you the advice it's got my escape in a some effective modern C++ book item 26 avoid overloading on numerous references so as I said before Scott called him universe reference many forwarding reference of course if you know what you're doing you're fine for the back-to-basics track this is the general advice that I would give you now there is indeed a couple of pitfalls basically if not covered the technical parts but still although we now know about the technical details we might stumble across a couple of yeah pitfalls things that go wrong because we do not pay attention things that go wrong perhaps because people do not completely understand the details and well I now designed this in a special way and so you now invited to participate in a new episode of who wants to become an R value reference expert and involuntarily you are the participants of this game show you now have to participate by thinking about the following problems problem number one I know half a okay simplified class a class a takes eighty ref ref and you see it is a templated constructor and I move my argument little T into my data member B now the question is of course not does B wants to have the T now the question that I basically have is is this semantically correct do I use the features that are just described in a correct way or not so entry question you have 15 seconds to think about it alright hopefully you all saw this this was kind of the entry level question and I heard the answer already I said three seconds yeah not one or two so it doesn't matter you should use not move this is basically basically a big big error this is what kind of reference this tariff ref a forwarding or universe reference I should not move unconditionally it could be an l-value and this is causing trouble at the call site I should need use a forward and exactly this form now it's perfect okay hopefully is something that never happens to you but this would indeed be a serious bug okay precious was too simple let's use this word let's take a look at this one example two now I have a class template and it takes its I it has a constructor that takes its argument as a t ref ref again I now forward my little T into my data member B again you're 15 seconds all right what is going wrong here and I've to admit this is indeed something I've seen a couple of times okay it's a lot of times a small number of times yes okay so you're correct I have unfortunately anticipated that I'm using a forwarding reference here T ref ref what kind of reference is T ref ref it is an r-value reference indeed this here is a class template parameter okay let's ignore this so the comment was to deduction rules okay T ref ref is in our value reference only in order to make this a photograph ins I need to type deduction in the function of course it needs to be a func template function templated constructor if it's only in arvalera fence and a for which it's not perfect this is sound not something that breaks things this is kind of harmless you will notice that this is not a forwarding reference because you will not be able to pass any kind of L value and since you only passed can pass our values then the forward would still do the right thing it still it's not really correct this is probably not what you intended the fix so this is an r-value references I said the fix would basically be to say let's move it's an arveleï reference let's should be moved but I doubt that this was the intention probably has to be redesigned probably want to make this a templated constructor I don't know okay please don't repeat this please take care that it's only a folding reference if it is using type deduction all right example three now I have two data members column B and C I have one argument again and now again half a templated constructor my argument my little T is forwarded into being and my little tea is forwarded into see again 15 seconds at least three all right a little oh sorry okay the second one can't fail you say I know what you mean so I would just want you a little more precise what should I not do what is the real mistake okay double move correct I am using forward twice forward is basically some kind of move it's obvious that I should not move something twice once it's moved from I cannot really move again it apparently is not so obvious that I also should not use forward twice because it's well the same thing if a person our value and if B happens to indeed move from this team then C is left with a move from object this is again a pretty bad situation this is something I have luckily only seen in test code for whatever reason but it and it was hard to under to make people understand that this is a move although it's called forward all right so do not use forward twice forward exactly once meaning I have to first copy T there's no other way I passed T to be B does too just creates a copy when whatever needs and then I can safely fourteen to see all right example for I now have again two data memories but I have also have two arguments the first argument is of capital T r1 and the second type of tau is of type capital T to my little t1 my argument is forwarded into David mmm a beam and my little teach who is forwarded in to see again 15 seconds to think about this one all right what's wrong here okay perhaps after us differently who feels this is absolutely correct Oh quite a number of hands meaning you actually feel this is okay have you have you considered the distinct possibility that these two refer to the same object but you're right it is absolutely okay so it can refer to the same object this is of course possible it can be the same l value so for instance I can call this constructor with two times T so opening parenthesis T comma T okay this is the same L value and overlays are fine they're not forwarded everything's okay but how do I call this function with the same r-value think about this I have to do something pretty bad I have to call its constructor with move T comma move T this is of course a serious error on the call site with just said we should not never move twice the basic idea of Narvel reference is this is a unique reference there is exactly one reference to this object exactly one and there folk you can safely forward here without having to think about potentially aliasing perfectly okay yeah okay I know it was messing with you and so it was interesting example five something that also on which is sometimes see now I have a function create create gets a couple of arguments these arguments are now perfectly for with it into the make unique function probably there's something we're happening here that's a little short we could use some make you need directly make unique returns unique pointer and then just to be a little more efficient we move the in a pointer from the function that's wrong here okay who spotted problem okay little out as I'm sorry perfect perfect answer you break copy elysian so this is not a buck in a sense of it does not work anymore this is a buck in the sense you actually pesum eyes your coach if this is a word it was I'm sorry not guaranteed that is true but okay very likely this function would actually return this very efficiently by means of something called a return ville a permutation also called copy lesion that is by the way the best thing a compiler can do for you if you return something from function in a return statement then this very likely will end up in the return value optimization most specifically in this case the named return well optimization because you partner has a name however as soon as you try to move something from the function this return immobilization is simply turned off yes this will be moved from function great but the move is indeed a pointer operation with rvo is kind of no opt you have no cause at all so this is kind of an anti-pattern do not move objects from a function it does not give you anything it does not improve anything do not move just properly return and since I basically don't do anything here in this small example I could simply return directly if this is possible do so this is now returning in our you do not give it a name and this gives you additional properties for instance in c-plus r17 this guarantees the return value conversation and of course this is much more valuable so whenever you have the opportunity to not name anything do not name it now this is kind of a general could use and like that would be great yes so this is something that I'm worried about so how do you know when you're gonna get our vo or not get our view because if that's a huge object and you don't get that our vo he's like all right fast ok this is what what I try to evade also in the rest of the talk so I mentioned it and of course that the Pandora's box has been opened um so the return validation is a pretty complex topping itself there's no guarantee that it gets so in this case I'm sorry in this case you get the guarantee this is easy + / 17 guarantee but in the general case you don't know however there is a something that you can rely on if the compiler cannot use our vo and it's a very first thing it tries then it falls back to move and so I don't have to do it explicitly so if our vo is not triggered at least I get a move for free and if move does not happen the last thing the compiler tries is a copy and if this doesn't work then of course the codis doesn't work you get a compilation error all right I have one more sorry okay sorry first earlier nevertheless so is there a way to force our do as I said in c-plus 17 there is the guaranteed understand and it says this example here we'll return it surprisingly even if it does not have a move constructor and not an copy constructor in this example it will be re out now I can return something cannot move that cannot copy from a function else you cannot force it it's a compiler optimization at least I'm not aware of any kind of to force it however this is a you know demonstration that exists in c-plus us 98 now with the years it has improved c-plus Islam gave you a little more guarantee since he passed 11 this became a mandatory optimization and I think compilers a pretty clever nowadays there is no way you can force it but you can rely on it pretty pretty well okay does does it affect if you use different compilation flags like Oh 201 release debug to enforce using return value optimisation interesting you know our hero is something they compile am I to right away it is for instance well there's a guarantee even if you compile with debug mode or zero this will return it so it's not switched off so this return value optimisation is kind of independent of the optimization already choose okay it's a little bit like you don't want to see the six example but okay go on can you go back to the previous right - which example to the previous just a previous yes one so yeah you peek here it's local variable we are talking our restaurants again a lot of echo okay move away a little bit from the mic and perhaps speak louder that this is makes it easy for me okay okay I do not return a reference in this case I do return by value okay yeah but perhaps your question is pointing is going in the direction I wanted to show anyway do not please return by reference even so not L value reference and also not arvind reference yeah this does not help at all you would return a reference to local object the reference would be invalid when it is returned your jig is already destroyed this is of course also an anti-pattern okay comment to make there's sort of two flavors of return back there's no return value corrective correctly the easy way to check what's going on is just to do it with a simple clasp right you can step in the debugger or you can just put some print statements what I found where I am is the older Solaris compilers don't do an overview so if you name it and return it you don't get it but the Linux compiler alright okay thanks for the comment always measure yep alright thanks for the cover all right example six okay my animation return returns reference local opting of course there is a core guideline don't return it to your RF apparently this is so common that there is even a core guideline so please don't do it so okay why is it valid why do they let you do it okay you have you're in charge in C++ you are the one who decides what is happening so perhaps it's a reason okay example six I now have a full function it takes again a floating reference now we see it for what it is the type that I get could be integral but it could be also something else I would like to this to deal with integral types differently so there is an if context per I use the type two it is integral if it is indeed integral I fall into this if branch and else I deal with this as a non integer something wrong here I promise fifteen seconds all right this is indeed tricky after admit I spent two hours of my life debugging this particular problem so I felt like sharing it's not a bad idea what is happening here so Pharaoh says it's about the team is integral tea unfortunately tea is not necessarily concrete type type deduction in case of an l-value would make the TA for instance widget ref and which dref is never an integral and so even if you pass an l-value integer int then this would be an int ref and this would also not be an integral so in other words this integral might fail although it's an integral type and so this does not exactly do what I intended to do what you have to do here what you cannot forget is okay animation again you should explicitly remove the reference it could be a reference based type the tea itself if you use the no ref type everything works as expected this is a little tricky but this is just part of this deduction rules this is part of the magic of forwarding references this is why a little more difficult to use okay we just a Mike please you should remove the context / okay the Const is by the way not a problem a constant is recognized as an int or as an integral the cons is not a problem but the ref is so I okay if you want to you can also remove the Const but this is what you have to do all right we are back here yes it was a tough piece of work I admit it is not one of the easiest features but still he managed within two hours to basically see the the technical details I believe on your wrote into more details you will have now a much much smoother path so now believe it or not this could be you this is you the new our Valley reference expert so thank you very much is there any more questions yeah this is Mike okay questions about that stack frame I don't really understand I don't know if it's the scope of this presentation to let me to understand how would a stack frame look like if I would you call a function that is okay now the acoustics is again perfect I call the function that a text document as there a flap which is itself calling the target function because since it's refreshed I would understand that modifying that object would land modification in the deeper in the stack am I correct okay do you mean I can call if what happens if I call myself kind of no no no simply its acoustics I'm sorry if I'm to avoid moving the object it means that the automatic variable still resides in a stack frame of my parent right yes correct which means that my automatic let's say referent if I modified this reference or not but if I simply call this referee body I cannot modify it it means I've been calling the something that is up in the stack correct so yes it's still on the stack the object you move from is honestech still it lifts on until it is finally destroyed yeah okay the second very simple question and I can have an int I princess the integer I can't have a reference to that integer the AI has a name this will be null value it would not pass to a ruffler function yes not a simple forget about the functions in this function body I can have a fiend is I don't know three then I could in reference J its I it means that I would be the reference a trance up J now I understand it wouldn't make sense to make a riff raff to the I somehow right okay I think this is hard to explain especially since you're trying to point out different things so let's take this offline I'm happy to answer the question perhaps you can show me a piece of code well if you mind other questions no alright then thank you very much [Applause]
Info
Channel: CppCon
Views: 24,384
Rating: 4.975194 out of 5
Keywords: Klaus Iglberger, CppCon 2019, Computer Science (Field), + C (Programming Language), Bash Films, conference video recording services, conference recording services, nationwide conference recording services, conference videography services, conference video recording, conference filming services, conference services, conference recording, event videographers, capture presentation slides, record presentation slides, event video recording, video services
Id: pIzaZbKUw2s
Channel Id: undefined
Length: 53min 49sec (3229 seconds)
Published: Mon Sep 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.