So far in this course.
Initializer list have been treated as a kind of C plus plus 11 construct.
And a bit like the bulletin arrays.
So, in fact, when you use the initializer list syntax using the braces here, the compiler actually
creates an instance of the templated initialize list class here.
So if an initializer list is used to initialize another type, for example, in this case the vector
here.
Uh, then the compiler creates an initialize list object and with the given values between the braces
here, so and the container object is initializing the initializer list iterator.
So this ability to create an initialized list object from a braced initializer list can be used to give
a function a variable number of parameters.
So I'll beat all of the parameters.
Must be the same type in this case here.
So in order to use this initializer list, we have to firstly include the initializer.
Initializer list.
Header file here.
And then we're going to create a new function named sum and.
But you can return the integer here.
Sum and initial.
List here and.
Then.
This initializer list will take the integer values here and make it values.
So this sum here takes the parameter values.
This will take one parameter and the type of initializer list integer here.
So which here integer sum equals zero here, for example.
And we're going to create a for loop integer values.
We're going to iterate throughout this parameter.
Values.
And with this for loop.
We're going to use this as the we're going to some increment, some by one at every or some by e here
at every iterating here.
And we're going to after this, we're going to return the.
Add some integer here.
So in the main function we're going to create, we're going to make actually the main function is going
to just print something and call this some, uh, function here that we created here.
So C out.
Some.
Here and.
End line.
Firstly, we're going to call just an empty sum and see out sum.
Here we're going to pass the values here.
In this case, we're going to pass the negative values starting from six minus six, negative six here.
Five, four, three, two.
One and here and line.
So.
C out.
Some.
And this case we're going to make give it a ten, 20, 30 and end line here.
So in this case, we're going to get the if we pass the NON-OBJECT to this some function, we're going
to get a zero.
In this case, we're going to get the -2021.
And in this case, we going to get the 16, as you can see here.
And the sum function here has a single parameter initializer list integer here, which can only be initialized
with the list of integers here.
So the initializer list class has a very few functions because it only exists to give access to the
values in the brace list here.
So most significantly, it implements a size function that returns the number of items in the list here.
So you can use values that size.
As you can see, this will return the number of items in the list.
Let me mention it.
So when you download this code, you're going to see.
Returns, number of items in the list.
So here.
And size function returns the number of items in the list.
So.
And the begin and end functions in return pointer to the first item in the list and to the position
after the last item.
So these two functions are needed to give iterator access to the list and it enables you to use the
object with with the range for loop here.
So as you can see here, we when we compile the code, we're going to get the zero -20.
Why 21 and 60 here?
So in this example, the main function here calls this function three times the sum function, three
times each time with the priest initializer list here, as you can see here.
So and the function will return the sum of some of the items in the list here.
And as you can see, it, will the sum here multiply or will some of the numbers in the list?
So clearly, this technique means that the each item in the variable parameter list has to be the same
type or type that can in can be converted to a specify specified type.
So you will have the same result if the parameter had been vector.
And the difference is that the initializer initializer list parameter requires the list initialization
here.
So if we make it like this two point make, give it the 2.1.
As you can see here, we are going to get error because the initializer list can only you can just only
pass the values that has the same type as this parameter here.