 Great, it's time to welcome you to another morning of the new project conference and I started out, I think I want to start it off with a little twist time but, or without the word for it, it's not very great or without the camera, but it's great, so I'll be... Okay, let's get into it. 18 months from start, two of you. Does it know anything about us? Everything about us? The same. So maybe you'll learn some things, I apologize, except for maybe some insight Hopefully, thank you very much for this. Is this not like the start? Defaults and deletions, new stuff or no longer new stuff? So, what part is this? What part is that? It's the most important part. The flyer. The flyer that the compiler can see is the size. Sorry, the flyer that the compiler can see is the size. The structure of the book, the structure of the book, the structure of the assignment and the user. The user? Yes. No. Nice job, buddy. Any questions? Which is another thing, because if you do some refactoring and you have some overloads, they only get rid of one of those overloads but they are very similar, so you'll never feel that maybe if I remove this overload, another one kicks in and I don't want to kick in. Just go for all the problems, combine them all today to be removed from the structure, define as needed and then combine it with the other one. Kick in and you're safe and you can fix those places and then remove them completely. So, deleting can do no more than any kind of function which kind of makes sense if you think about it why only some of them can see. Now we're going to step seven, which of them can be defaulted. You can find that in the library as soon as that. Exactly. Just some special member functions. So the default constructor, default constructor, the destructor, copy constructor, the copy, the move constructor, the copied assignment operator, the move assignment operator. These are the ones that can be defaulted. Why just these ones? Why much arbitrary ones? Of course, if you should combine them together for this do what I mean function, no idea what to default and go for that. But for these ones, it always involves clear distractions. For example, the constructor, the default constructor just default construct all the members, the default, the destruct, destruct all the members and then copy the move ones and copy all the members. Easy thing. Exactly. But I can't. So in the function just watch the word. It's very important to watch the tiny details. The deleted ones are defined. The declared ones, the defaulted ones are really declared and there's no definition for your place where you declare that it's defaulted. And the deleted one is defined as deleted. There's no body coming. For the defaulted ones, there might be a body coming not from the type, but from the size of you. But in the function of the way, defaulted and deleted and then it's defined and defined. The world will enter and often don't have any of these special functions declared and complied with the declared ones on us. But in this case, we also have a pointer member that can be copy constructed. So the compiler for defaulted declare as defaulted function then the compiler takes in and just in this case copy constructs all the members. But we can't copy construct by then because the unique pointer doesn't by this name for the reason doesn't have a copy constructor. So what can the compiler do in this case? Of course, the wall to end implemented because there's no way to implement a copy constructor or a destructor or a destructor because one of the members or one of the base classes doesn't have this operation and the compiler will just say okay, you want it, I can actually do a bunch of define as needed. Is there a difference between defining and defaulted and just leaving it out? No, in this case more. There is sometimes a difference whether you have it. So there is a special case just one more question on this synthesizer or the function also being defined as only defined as default not declared as a legitimate way to structure the code so you don't want to have the constructor inline because you don't want to have a stable API so you want to have this function to be called from the other line and not inline there. So you have a new code file you just have a normal declaration of the constructor and then in the CXS file you can then say just insert here the defaulted code for it and that works fine and that is, as I said in a nice way, you don't have to spell it out down there even if you want the constructor not to be denied in your code file. The other way about declared functions are never defined so you don't have to complain about the calling which is illegal and in the scenario the same and it is defaulted and if there is so what the standard says a constructor or a destructor a copy assignment operator or a copy constructor then the other copy functions just have a copy constructor and if the assignment operator implicitly gets declared for you or implicitly defined as defaulted for you and if there is a destructor for the move operation the rules are safer so if you have any special number functions move operation is not needed and you need to explicitly define them as defaulted which makes sense if the destructor does something special you probably want to move operations to also do something special to not allow any moves and if you have a destructor that does something special like to beat a member then you probably also a member point and you also don't want to have a calling constructor because you then have to delete the member if you don't take care so these old rules are seen as bad and these old rules are not that good and if you have a destructor for example your copy operations your copy constructor the assignment operator is still implicitly defined for you but that will go away in future versions probably for rather good reasons so what GCC9 today is GCC version that is in the words now that is generally a warning for that and without our onyx and arrows enabled we get an error for all these places where we have some of the member functions implemented and the others kicking in implicitly so what I did with the code is I went for all that code there are some places where there were blocks because we had one full space from the other and then there were really blocks working there but in many cases what we have is for example the class of the virtual destructor that is even spelled out here the rules now say that we have a virtual destructor or any sort of destructor that these special member functions will no longer be defined implicitly defined as the folder for you but will be implicitly defined as the agent for you so what I did is add all those people but more what I did not copy for example the copy constructor that we defaulted which is the file as the agent it's just dangerous if there's any members like bunch of members if we then default move operations you know of course we will double delete stuff or if we default the copy operations why do we actually destructor it? that's just an example of how we go for those we have a virtual destructor that will make a version of all the tools if we now have any destructor the implicitly defined functions will in the future go longer so we need to take action now and that's why we have to get some more data across the code base so if you stumble across any of these it's just to a big future compile versions we have to hurry to get all the inside of topics next up in-line what's an in-line function? it's not about in-line anything it is more about having that one function defined in multiple places so multiple inflation units as they are called can contain the same definition if the definition is different whether it's cheating or compile whether one knows about the world will end in that case the linker will not decide because it doesn't have to put in a clever linker a small program organization that one might notice but the non linker won't because if you have the same feature of the function just different bodies which is especially useful at least in-line functions then contain static data because there is only one instance of the static data your counter function can be in-line to the root root file and you can return increasing values regardless of how you call it that's a normal trick this is in-line variables what's in-line variables same thing can be defined in multiple translation units what's that before define to what you define exactly so what we did with backdrops in the past is make the definitions of literal values we can now do with context group so if you have static data context group like we have in some places no one will just run through all the code and all the strings that we use as defined many of them are now changed into context group, static member data members and the trick with these is context group for functions as well as for variables implicitly implies in-line so whenever you have something that is context group in-line and in-line variables so before that they were not in-line variables it's slightly different and with the in-line variable this one is the definition already so you don't need an extra definition for the memory that this variable might need because the compiler not takes care of that in the same way for functions the static most expert is that we love it aren't context makers static by definition no, no, no we can also have one static context group the context will be redundant once expert variable wants but the static is not redundant so once I'm in my next class they won't talk about that we have context group static members member data members that we can now define in the body of the class and in the past you needed before C++ 17 you also needed to have a so this was only a declaration back then you had an initializer and you also needed to have a definition but in some places the compiler don't have a definition the root part or the legal part so until C++ 17 in some places especially if the literal is of some class type not just of some integer type we also have to have in some of the CXX files this incantation here if we don't yet have C++ one variable we also need to provide a definition of this member and once we move to C++ 17 completely and throw out all the old compilers we can remove these lines so we now have some special config variable that controls that so if you stand across this in the code you'll get a bigger error for something construct like a memory member to just sort this incantation from now copy and move C++ 17 to this compiler so we have a struct with a deleted copy constructor even if there is no const there it is deleted so we just have one copy constructor implicitly defined so this is the one so it is deleted so we don't get any other ones so we can't copy there is no copy happening it is deleted exactly there is a guaranteed copy division in C++ 17 so this temporary thing where this power value gets directly created in the space of the assets initialized there so this works now which is wonderful because we sometimes want to have factories for objects that contain unique pointers so this is why they made this word actually and you can create it if you try to respond and use to move on that meter that's the next slide before that we'll work on the compiler next one slide is different but this one is compiler so the only thing we change is we first construct the s object here down here in the s function and then move it out does that work? the copy constructor doesn't by definition this s object which is an L value has to be copied out of here even if the compiler is smart it has the optimal copy division so there is no guaranteed copy division in this case where the object is an R value if the object confirms it's an L value the copy division has always been the case but as it has always been the case even if this option of copy division is done the copy constructor still needs to be callable which it isn't here so there is still a subtle difference so if you write these factory functions you need to make sure that the factory or that it joins the real object and not something that gets copied now standard move as I said if you insert the standard move here it's that good or that in the worst case it's that so the compiler and many of the compilers are smart enough to warn you that you're doing a pessimizing move so what happens when playing return s would still be eligible for this optional copy division that we saw on the previous slide on the lower part the compiler might or might not do that so if it does that then the playing return s is optimized the non-playing return standard move that adds some casting around the s then the rule doesn't go longer this can be optimized now because the rules are quite big you're playing return of some variable can be optimized so either we can optimize that the compiler is smart enough and optimizes it but if it doesn't then the standard move might be useful now rules, tricky as they are say if the compiler doesn't optimize here with the playing return s here without any standard move decoration then the compiler must first try to do a move for you we didn't talk about complicated rules but in the end they do what we would expect try to move it out as deeply as possible for you and that's the reason why sometimes such a standard move if you edit, it will be a challenge but the compiler says no you've let out, better you've let out it won't do any good so next one I'll just start at 20 minutes this will go better so we have a struct s again we now have some other struct t that we want to return and we have some conversion constructor that can take an ascent turn it into a t and it takes it by r value of reference so it's a moving kind of moving thing into a t and what we want to have from the end is a t so this struct that New Yorker it's not really that bad as the other one it's not a pessimizing move but it still will give you warnings from some compilers that is a redundant move because they have to adapt it over the time I come back to that if you just have to return s they have to play s between s and that's again something special that allows to take this l value s and then treat it as an r value to directly move it into the constructor so whenever you see a return of just a variable and nothing else or decoration around that's all that's about and then some special moves begin and you will automatically get these thousand moves so in this case it isn't very exact that it will generate some compilers a warning you have there that makes your build again but the compiler will tell you that this is redundant and just be removed next one the only challenge is to make that cheap constructor exquisite because we don't want to move we need to construct t here and we need to explicitly mention t so we don't have a plane which are s we can't have a plane which are s in many cases because we need to express the tower or write down and we want to construct a t because the constructor is exquisite and if we leave out the t around that in our compiler and if we don't insert a standard move and I'll let you hear the s that were not removed so we're customizing that and using a public construction instead of a move so this is one of the rare cases for example they're better than the necessary and the last one just to democratize the last one of these moves slightly different situation again we have a base class as one we have to rewrite the class as two we have a base we want to return the base we generate we write the class instance should we move that out or not should we move or not should it depends what happens when we move the base to us out invoke its move operation whatever it does it then we move the object into some other state that is still safe but some members are probably in a state where they have off their content now with the right class is fine with that and everything is good if the right class is rather trivial and it doesn't depend on the state of the base class then no harm done if we just move some parts of the base some parts will be left untouched by this move so we have the more objective and rather Frankenstein state where the base class part is moved out and the right class part still think oh I have a fully intact base class part which is not the case here so you have to know that this is still their base so we come around here in this case there is another special group so it will normally be eligible for a move but then the compiler sees no we change the type of that the move on structure that we would actually pick is not for S2 but it's for S1 and then it doesn't use them as a constructor for you so in this case you have to decide for yourself movement this is the Frankenstein temporary that has parts only parts of a move or use a copy and so sometimes you might have to resist the warnings that they generate at least one amount of data maybe later versions will fix that properly is the inner S2 the structure there is a problem so the derived class is a new class so I moved out parts of it whatever the structure meant so if you have a special structure all the original data that depends on the inner class parts that will be there and who will have the supervisor break up or if the class was designed and it doesn't care about the features of its base class members then everything will be fine but it really depends on how you so I am going to ask because some players didn't get the light either for some time and some things changed there is the rules how things are done so there are some parts of the code where we have some special if there is a trick to be again formed out because the rules for the second case we have the S and the T where we have a different class and a different type that we moved out in the olden times we didn't even move in fixed rules so we had some of these and with the last example it gets even worse because GCC has a bug there and even with the bug fixed again it still generates a warning so we have some problems like what was right there and with this it can be formed jungle or what was if you again see you