So far In this course, initialize lists have been treated as a kind of C++ 11 construct and a bit like
the built in operation.
So in fact, when you use the initialized list syntax using the braces here, the compiler actually
creates an instance of the templated initialize list class here.
So if an initialized list is used to initialize another type, for example, in this case the vector
here.
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 initialized list iterator.
So this ability to create an initialize list object from a braced initialize list can be used to give
a function a variable number of parameters.
So weight all of the parameters must be the same type in this case here.
So in order to use this initialize or list, we have to firstly include the initialized.
Initialize the list.
Hit the file here, and then we're going to create a new function named E some and.
We can return the integer here some and inch.
List here and.
Then.
This initialize the 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 initialize or list integer here.
So which here?
Integer sum equals zero here, for example.
And we're going to create a false integer values.
We're going to iterate throughout this parameter.
Values and the test for love.
We're going to use this as the 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.
Some integer here.
So in the main function, we're going to create.
We're going to make a actually, the main function is going to just print something and call this sum
function here that we created here.
So see out.
Some.
Here and.
And blind virtually.
We're going to call just an empty some and see out some 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 or three to.
One here and one.
So.
See out see out some in 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 a the non object to this some function, we're going to
get zero.
In this case, we're going to get the -2021.
And in this case, we kind of get the 16, as you can see here.
And the sum function here has a single parameter.
Initialize a list integer here, which can only be initialized with the list of integers here.
So the initialize list class has a very few functions because it only exists to give X to the values
in the brace list here.
So most significantly, it implements a size functions 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.
But let me mention it.
So when you know this code you're going to see.
Returns, number of items in the list.
So here.
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 width with the range for loop here.
So as you can see here, we when we compile the code, we're going to get zero -25, 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 breast.
Initialize the list here as you can see here.
So on the function we return a sum of some of the items in the list here.
And as you can see it, will this sum here multiply or this 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, specify type.
So you will have the same result if the parameter had been vector.
And the difference is that the initialize, initialize or list parameter requires the list initialization
here.
So if you make it like this two point make, give it 2.5.
And as you can see here, we are going to get error because the initialize list can only you can just
only pass the values that has the same type as this parameter here.