 Hello and welcome back. In this lecture we're going to discuss some concluding comments on the C++ standard library. Here is a quick recap of what we have been studying in the last few lectures. We have basically been studying about specific classes in the C++ standard library. In particular we have studied about the string class, the vector class, the map class and the list class. In this lecture we're going to discuss some issues about passing container objects as function parameters and function return values. We're going to discuss about the use of type def to simplify complex container class definitions and we are also going to see a very high level overview of some useful C++ standard library modules beyond the ones that we have already studied. Some parts of this lecture are motivated by the treatment in the book and introduction to programming through C++ by Abhiram G. Ranade published by McGraw Hill Education in 2014. Now we have studied about container classes in the last few lectures. Specifically we have studied about vectors, maps and lists and we've also seen how to write simple programs that use these container classes. Now what if I wanted to pass container objects as parameters to a function and specifically suppose I wanted to pass these parameters by value. So here is an example of a function where this function takes two parameters v1 and m1, v1 is a container object, it's a vector of integers, m1 is also a container object, it's a map with key type string and value type int. Now since these two parameters are being passed by value, therefore the vector v1 and the map m1 are going to be copied to the activation record of func1 when func1 is invoked. Now how is this copying going to get done? It is actually going to be achieved by invoking the copy constructor of vector instantiated with int and of map instantiated with string and int and the default copy constructors are simply going to copy the values of all data members of the object that is being passed as a parameter to the activation record of func1. So in this particular case all the integers in the vector of integers that is being passed as a parameter will be copied element by element to the activation record of func1. Similarly in this case every key value pair in the map that is being passed as a parameter will be copied key value pair by key value pair to the activation record of func1. Now as you can appreciate that this process can be highly inefficient both time and memory wise if the container objects that we are passing as parameters are large. So what could be an alternative way of passing container objects as parameters? Well we could pass them by reference. So here is an alternative form of the same function func1 but here I have passed the parameters v1 and m1 by reference and if you recall when we pass parameters by reference basically pointers to those parameters are passed to the called function. So really there is no copying of data member values to the activation record of func1 and therefore this is far more efficient in general than passing container objects by value. Of course since just the pointers to v1 and m1 are going to get passed when I pass parameters by reference it is easy to see that the time and memory overhead in this case are actually independent of the size of the container objects that are being passed as parameters and this is certainly a desirable thing. Well but if you pass parameters by reference there is a certain risk that you incur which is that the cally function might end up modifying the parameters that you passed as reference even though you did not intend them to be modified. So if you really want to prevent the cally function from modifying the parameters you're passing by reference you can use the const keyword in the declarations of the parameters as I've shown here and once you do that if in the body of func1 it tries to modify either the parameter v1 or the parameter m1 the compiler will complain and report an error. So the bottom line is that container objects can have huge memory footprints and so when you are passing container objects as parameters to functions you need to choose the parameter passing mechanism with discretion. If your container objects are always going to be small then you can pass them by value but otherwise it's always preferable to pass them by reference. Now what happens if a function tries to return a container object? So for example here the function func2 is trying to return a map with key type string and value type double. So in this case func2 must compute a certain map and when it tries to return that map the map that it computed is going to be copied to the activation record of the caller function when func2 returns. Now how is this copying going to get done? It will actually be done by invoking the copy constructor of the map class instantiated with string and double for the key type and the value type and once again what is that copy constructor going to do? The default copy constructor is going to copy every key value pair from the map that func2 is trying to return to the activation record of the caller function. Every key value pair is going to get copied and this can indeed be very inefficient if the map is large. So what might be an alternative way of returning a map from a function? So here is an alternative way to do that. Here I have passed an additional parameter to the function so I'm calling it alternative func2 and this additional parameter is actually a reference to a map with key type string and value type double just like what this func2 was trying to return. So essentially I'm saying that let the caller function create a map with key type string and value type double perhaps an empty map and pass a reference to this map to the call a function and then the call a function can simply fill in or modify this map since it is passed by reference and it is not declared as const the call a function can indeed modify this and because it is passed by reference when the call a function returns the caller function can see the changes made by alt func2 in this map. Note that I have declared this parameter as a constant so this parameter can only be read by alt func2 just like it was the case here it cannot be modified however this parameter is actually being used to return the map computed by func2 so I have not declared as const because I do want this alt func2 to actually make changes to this map and that is how alt func2 is going to convey its result back to the caller function. So since no copying of result map is needed here avoiding copying of the result map basically leads to a lot of efficiency and therefore this option of making a function return a map is going to be far more efficient in practice than this option. Now we have also seen in the last few lectures that we could define container classes where the basic objects are complex data types and they themselves could be other container objects so for example here I have a very complex container class which has a map of double and list v3 and then a map of string and that map and then a vector of that and as you will appreciate declarations like this are fairly difficult to read understand as well as modify c++ actually provides a very nice feature called type diff to simplify such declarations so using type diff I can actually give custom names to types for example I could say type diff list v3 list of v3 so now list of v3 is a name that I have assigned to this type and wherever I use list of v3 the compiler will understand that I'm talking about the type list v3 once I've defined this name for this type I can use that name in another type diff so here I'm saying type diff map double list of v3 and the name I'm giving to this type is map double list of v3 so note that what I defined using type diff here is being used here in another type diff and what I'm defining using type diff here is now going to be used next inside another type diff so I'm saying type diff map string map double list of v3 this entire type will be denoted by my type and then vector of my type will be denoted by wek of my type through another type diff and finally my wek the variable that I wanted to declare is going to be of type wek of my type so as you can see systematically I have assigned custom names to various types and use those custom names to define other types so that finally when I look at the declaration of my wek over here it's much clearer to understand it's much clearer to modify of course type diff can be used not only with container classes but they can also be used even with primitive types for example I could write type diff int my int and then I could use my int as an alias for the type int everywhere in my program now in our study of the c++ standard library we have encountered only a very small subset of modules and classes defined in this library there are several other useful classes and modules defined in this library and here I've tried to list a few other useful container classes in the c++ standard library these are q class the deck class and the stack set and forward list classes the forward list class is like the list class we have seen but it has only links in the forward direction the set class is for representing sets of objects the stack class is for representing stacks which are basically used to store and retrieve elements in a last and first out order the q class is for storing and retrieving elements in a first and first out order and the deck class is basically a double ended queue where you can insert as well as remove elements from both ends of the queue similarly the c++ standard library also has several other useful libraries of utilities and once again I have listed here only a very small subset the algorithm library contains a lot of useful utilities for example it has utilities for sorting arrays for sorting vectors for sorting lists the complex library has utilities for representing and manipulating complex numbers the exception library has features that allow you to do exception handling in your program the random library provides pseudo random number generators the memory library has features that allow you to do dynamic memory management and similarly there are a whole bunch of several other useful libraries of utilities I encourage all of you to read more about these various features classes and modules available within the c++ standard library there are several excellent online references which describe this library and here I've listed two of them www.c++.com slash reference and of course the material available on Wikipedia there are of course other online references also and I would encourage all of you to read more about the c++ standard library so in summary in this lecture we saw how container classes can be used in function calls how parameters which are container objects can be passed and how container objects can be returned from functions we saw the use of the type def construct to simplify complex container class definitions and we also saw a very very high level view of some useful modules in c++ standard library beyond those that we have already studied in earlier lectures as I have said it's highly recommended that you read more about c++ standard library and also use it in your programs this collection of utilities classes and features is extremely well designed it has been thoroughly tested by users from all over the world and it's also very well documented so if you can use features that are already built in the c++ standard library in your programs you already save a lot of coding testing and debugging effort thank you for your attention