1 00:00:00,970 --> 00:00:08,350 So far In this course, initialize lists have been treated as a kind of C++ 11 construct and a bit like 2 00:00:08,350 --> 00:00:09,400 the built in operation. 3 00:00:09,430 --> 00:00:17,650 So in fact, when you use the initialized list syntax using the braces here, the compiler actually 4 00:00:17,650 --> 00:00:23,470 creates an instance of the templated initialize list class here. 5 00:00:23,470 --> 00:00:30,280 So if an initialized list is used to initialize another type, for example, in this case the vector 6 00:00:30,280 --> 00:00:30,880 here. 7 00:00:34,670 --> 00:00:44,470 Then the compiler creates an initialize list object and with the given values between the braces here 8 00:00:44,480 --> 00:00:51,250 so and the container object is initializing the initialized list iterator. 9 00:00:51,260 --> 00:00:59,150 So this ability to create an initialize list object from a braced initialize list can be used to give 10 00:00:59,150 --> 00:01:01,370 a function a variable number of parameters. 11 00:01:01,370 --> 00:01:06,190 So weight all of the parameters must be the same type in this case here. 12 00:01:06,200 --> 00:01:11,990 So in order to use this initialize or list, we have to firstly include the initialized. 13 00:01:13,180 --> 00:01:14,470 Initialize the list. 14 00:01:15,100 --> 00:01:23,200 Hit the file here, and then we're going to create a new function named E some and. 15 00:01:24,040 --> 00:01:28,630 We can return the integer here some and inch. 16 00:01:34,530 --> 00:01:36,360 List here and. 17 00:01:37,390 --> 00:01:38,020 Then. 18 00:01:42,470 --> 00:01:48,080 This initialize the list will take the integer values here and make it values. 19 00:01:48,860 --> 00:01:52,760 So this sum here takes the parameter values. 20 00:01:52,790 --> 00:01:58,350 This will take one parameter and the type of initialize or list integer here. 21 00:01:58,370 --> 00:02:00,080 So which here? 22 00:02:00,080 --> 00:02:04,050 Integer sum equals zero here, for example. 23 00:02:04,070 --> 00:02:07,940 And we're going to create a false integer values. 24 00:02:08,720 --> 00:02:11,600 We're going to iterate throughout this parameter. 25 00:02:12,670 --> 00:02:16,120 Values and the test for love. 26 00:02:16,210 --> 00:02:28,660 We're going to use this as the going to some increment, some by one at every or some by e here, at 27 00:02:28,930 --> 00:02:30,340 every iterating here. 28 00:02:31,290 --> 00:02:35,040 And we're going to after this, we're going to return the. 29 00:02:36,300 --> 00:02:37,980 Some integer here. 30 00:02:38,370 --> 00:02:41,280 So in the main function, we're going to create. 31 00:02:41,940 --> 00:02:48,420 We're going to make a actually, the main function is going to just print something and call this sum 32 00:02:49,170 --> 00:02:50,940 function here that we created here. 33 00:02:51,570 --> 00:02:53,280 So see out. 34 00:02:55,000 --> 00:02:55,720 Some. 35 00:02:57,310 --> 00:02:59,110 Here and. 36 00:03:00,070 --> 00:03:01,390 And blind virtually. 37 00:03:01,390 --> 00:03:07,780 We're going to call just an empty some and see out some here. 38 00:03:07,810 --> 00:03:09,520 We're going to pass the values here. 39 00:03:09,520 --> 00:03:16,510 In this case, we're going to pass the negative values starting from six minus six, negative six here, 40 00:03:18,010 --> 00:03:22,840 five or three to. 41 00:03:23,910 --> 00:03:27,480 One here and one. 42 00:03:28,920 --> 00:03:29,880 So. 43 00:03:30,730 --> 00:03:41,320 See out see out some in this case, we're going to make give it a ten, 20, 30 and end line here. 44 00:03:41,440 --> 00:03:50,950 So in this case, we're going to get the if a the non object to this some function, we're going to 45 00:03:50,950 --> 00:03:51,850 get zero. 46 00:03:51,880 --> 00:03:55,780 In this case, we're going to get the -2021. 47 00:03:55,810 --> 00:04:03,010 And in this case, we kind of get the 16, as you can see here. 48 00:04:03,010 --> 00:04:06,340 And the sum function here has a single parameter. 49 00:04:07,210 --> 00:04:14,770 Initialize a list integer here, which can only be initialized with the list of integers here. 50 00:04:14,890 --> 00:04:21,760 So the initialize list class has a very few functions because it only exists to give X to the values 51 00:04:21,760 --> 00:04:23,430 in the brace list here. 52 00:04:23,440 --> 00:04:32,620 So most significantly, it implements a size functions that returns the number of items in the list 53 00:04:32,620 --> 00:04:32,830 here. 54 00:04:32,830 --> 00:04:35,440 So you can use values that size. 55 00:04:35,470 --> 00:04:40,660 As you can see, this will return the number of items in the list. 56 00:04:40,960 --> 00:04:42,160 But let me mention it. 57 00:04:42,160 --> 00:04:44,740 So when you know this code you're going to see. 58 00:04:45,610 --> 00:04:50,710 Returns, number of items in the list. 59 00:04:51,550 --> 00:04:52,660 So here. 60 00:04:54,260 --> 00:04:58,220 Size function returns the number of items in the list. 61 00:04:58,220 --> 00:04:59,330 So. 62 00:05:00,760 --> 00:05:07,750 And the begin and end functions in return pointer to the first item in the list and to the position 63 00:05:07,750 --> 00:05:09,100 after the last item. 64 00:05:09,130 --> 00:05:17,020 So these two functions are needed to give iterator access to the list, and it enables you to use the 65 00:05:17,020 --> 00:05:20,780 object width with the range for loop here. 66 00:05:20,800 --> 00:05:29,650 So as you can see here, we when we compile the code, we're going to get zero -25, 21 and 60 here. 67 00:05:29,920 --> 00:05:36,490 So in this example, the main function here calls this function three times the sum function three times 68 00:05:36,490 --> 00:05:38,310 each time with the breast. 69 00:05:38,320 --> 00:05:40,900 Initialize the list here as you can see here. 70 00:05:41,320 --> 00:05:47,750 So on the function we return a sum of some of the items in the list here. 71 00:05:47,770 --> 00:05:56,680 And as you can see it, will this sum here multiply or this will some of the numbers in the list? 72 00:05:56,680 --> 00:06:02,770 So clearly this technique means that the each item in the variable parameter list has to be the same 73 00:06:02,770 --> 00:06:09,100 type or type that can in can be converted to a specify, specify type. 74 00:06:09,100 --> 00:06:14,320 So you will have the same result if the parameter had been vector. 75 00:06:14,320 --> 00:06:21,820 And the difference is that the initialize, initialize or list parameter requires the list initialization 76 00:06:21,820 --> 00:06:22,180 here. 77 00:06:22,180 --> 00:06:26,830 So if you make it like this two point make, give it 2.5. 78 00:06:26,830 --> 00:06:32,740 And as you can see here, we are going to get error because the initialize list can only you can just 79 00:06:32,740 --> 00:06:38,050 only pass the values that has the same type as this parameter here.