1 00:00:00,349 --> 00:00:02,932 (lively music) 2 00:00:05,250 --> 00:00:06,270 Frank: Okay, welcome back. 3 00:00:06,270 --> 00:00:07,740 In this video, we'll finish off 4 00:00:07,740 --> 00:00:09,750 what we started in the previous video. 5 00:00:09,750 --> 00:00:12,450 So let's get a little bit more complicated now 6 00:00:12,450 --> 00:00:14,310 and look at a couple more examples. 7 00:00:14,310 --> 00:00:17,103 I'm going to reduce this a little bit here. 8 00:00:18,360 --> 00:00:20,280 All right, so here's test four 9 00:00:20,280 --> 00:00:22,170 and I've got two pieces to test four. 10 00:00:22,170 --> 00:00:23,580 Let me expand them both and I'll 11 00:00:23,580 --> 00:00:24,870 I'll walk through them. 12 00:00:24,870 --> 00:00:28,140 The first one, I have written a function 13 00:00:28,140 --> 00:00:30,663 and that function is called filter_vector. 14 00:00:31,500 --> 00:00:33,510 It's right here. 15 00:00:33,510 --> 00:00:36,300 It returns nothing and what does it expect? 16 00:00:36,300 --> 00:00:40,740 It expects a std vector of integers and its const 17 00:00:40,740 --> 00:00:43,560 so I cannot modify it from in here. 18 00:00:43,560 --> 00:00:46,830 It's called vec and a std function. 19 00:00:46,830 --> 00:00:47,970 That's a function object. 20 00:00:47,970 --> 00:00:50,220 And what does that function object expect? 21 00:00:50,220 --> 00:00:51,150 An integer. 22 00:00:51,150 --> 00:00:53,220 What does it return? A boolean. 23 00:00:53,220 --> 00:00:54,870 That's what the syntax says. 24 00:00:54,870 --> 00:00:57,180 I know the syntax may look a little wonky but 25 00:00:57,180 --> 00:00:58,980 it just a matter of getting used to it. 26 00:00:58,980 --> 00:01:00,570 It's not complicated. 27 00:01:00,570 --> 00:01:03,270 And what is the name of that parameter? Func. 28 00:01:03,270 --> 00:01:05,010 This is a function object. 29 00:01:05,010 --> 00:01:07,170 So I can call that function object 30 00:01:07,170 --> 00:01:11,460 simply by saying func and passing an integer into it. 31 00:01:11,460 --> 00:01:12,360 Any kind of integer, 32 00:01:12,360 --> 00:01:14,940 whether it's a literal or a variable name. 33 00:01:14,940 --> 00:01:18,630 And this guy will return a boolean that I can use. 34 00:01:18,630 --> 00:01:20,520 So that's what's really happening here. 35 00:01:20,520 --> 00:01:22,500 I'm displaying the left bracket 36 00:01:22,500 --> 00:01:24,690 and then I've got a range base FOR loop here 37 00:01:24,690 --> 00:01:26,943 that's looping over this vector. 38 00:01:27,840 --> 00:01:31,590 And for each integer I in the vector, 39 00:01:31,590 --> 00:01:34,110 I'm calling func and passing it in. 40 00:01:34,110 --> 00:01:36,330 What does this func do? I have no idea. 41 00:01:36,330 --> 00:01:37,980 That's the real power here. 42 00:01:37,980 --> 00:01:41,670 I could care less what is happening in that function. 43 00:01:41,670 --> 00:01:43,260 All I know is that 44 00:01:43,260 --> 00:01:46,530 I'm a filter vector function and I get a function. 45 00:01:46,530 --> 00:01:47,580 I'm calling that function. 46 00:01:47,580 --> 00:01:48,690 I really don't know what it does. 47 00:01:48,690 --> 00:01:50,400 I don't care what it does. 48 00:01:50,400 --> 00:01:52,020 The only thing that's important is that 49 00:01:52,020 --> 00:01:54,270 it expects an int and returns a bool. 50 00:01:54,270 --> 00:01:56,640 So in this case if it returns true, 51 00:01:56,640 --> 00:01:58,210 I'm gonna display that value 52 00:01:59,430 --> 00:02:02,130 and then I'm just closing this with a bracket. 53 00:02:02,130 --> 00:02:03,270 Okay, so it will make sense now 54 00:02:03,270 --> 00:02:04,350 when you see when I call it 55 00:02:04,350 --> 00:02:07,140 so let me scroll up just a little bit. 56 00:02:07,140 --> 00:02:08,669 I'm right here on test four. 57 00:02:08,669 --> 00:02:12,840 So I'm saying test four, that's right here. 58 00:02:12,840 --> 00:02:16,120 Here's my vector of numbers called NUMs 59 00:02:17,304 --> 00:02:18,360 and I'm gonna call filter_vector 60 00:02:18,360 --> 00:02:21,693 and I'm gonna pass in NUMs, that's this guy. 61 00:02:22,950 --> 00:02:25,230 And now I'm gonna pass in the function 62 00:02:25,230 --> 00:02:27,030 that I want called every time in here. 63 00:02:27,030 --> 00:02:29,700 Well I'm gonna pass in the lambda expression. 64 00:02:29,700 --> 00:02:33,780 Stateless, it expects an int and it returns a boolean. 65 00:02:33,780 --> 00:02:35,703 That's exactly what we set up here. 66 00:02:36,540 --> 00:02:38,520 So what is this guy gonna do? 67 00:02:38,520 --> 00:02:42,360 It's gonna return true when X is greater than 50 68 00:02:42,360 --> 00:02:44,370 and this guy here will be true 69 00:02:44,370 --> 00:02:47,400 only whenever each one of those I's is greater than 50. 70 00:02:47,400 --> 00:02:48,900 So what does this do? 71 00:02:48,900 --> 00:02:52,350 This only prints out values that are greater than 50 72 00:02:52,350 --> 00:02:53,820 right there. 73 00:02:53,820 --> 00:02:56,460 60, 70, 80, 90, a 100. 74 00:02:56,460 --> 00:02:59,250 In this example, I'm just using a different lambda. 75 00:02:59,250 --> 00:03:02,070 I'm only gonna display values that are less than 76 00:03:02,070 --> 00:03:02,903 or equal to 30 77 00:03:02,903 --> 00:03:04,707 and you can see them display right here. 78 00:03:04,707 --> 00:03:07,350 And in this case, I'm only displaying values 79 00:03:07,350 --> 00:03:09,150 that are greater than or equal to 30 80 00:03:09,150 --> 00:03:10,500 and less than or equal to 60 81 00:03:10,500 --> 00:03:13,650 so we're displaying 30, 40, 50, 60. 82 00:03:13,650 --> 00:03:14,580 This is pretty cool. 83 00:03:14,580 --> 00:03:16,440 I think you can really wrap your head around this 84 00:03:16,440 --> 00:03:18,870 and see how powerful these lambdas are. 85 00:03:18,870 --> 00:03:21,330 Also what's very important to understand is 86 00:03:21,330 --> 00:03:25,830 the programmer that wrote this function 87 00:03:25,830 --> 00:03:29,550 doesn't really care what this function does. 88 00:03:29,550 --> 00:03:32,040 Right here for example, only greater than 50 89 00:03:32,040 --> 00:03:33,450 less than equal to 30, 90 00:03:33,450 --> 00:03:35,940 it's up to perhaps another programmer 91 00:03:35,940 --> 00:03:38,640 that's using this filter_vector function 92 00:03:38,640 --> 00:03:41,013 to decide, you know, what's the logic here. 93 00:03:42,017 --> 00:03:44,370 Okay, now this guy right here 94 00:03:44,370 --> 00:03:46,230 is called the predicate lambda 95 00:03:46,230 --> 00:03:49,980 and I mentioned that in the slides in the previous lecture. 96 00:03:49,980 --> 00:03:54,060 This is a predicate lambda because it expects 97 00:03:54,060 --> 00:03:57,360 one or more parameters and returns a boolean. 98 00:03:57,360 --> 00:03:59,850 That's the definition of a predicate lambda 99 00:03:59,850 --> 00:04:01,710 or a predicate function if you will. 100 00:04:01,710 --> 00:04:04,710 So again, walk through this example and try 'em out 101 00:04:04,710 --> 00:04:07,470 and you know change these lambdas to do different things 102 00:04:07,470 --> 00:04:10,140 and you can see just how powerful this really is. 103 00:04:10,140 --> 00:04:12,030 There are so many algorithms 104 00:04:12,030 --> 00:04:13,500 in this general template library 105 00:04:13,500 --> 00:04:16,050 that use these predicate lambda just like this. 106 00:04:16,050 --> 00:04:18,510 So from a programmer's perspective, 107 00:04:18,510 --> 00:04:20,370 we're working in here, right? 108 00:04:20,370 --> 00:04:23,790 But the person or the team that wrote those algorithms 109 00:04:23,790 --> 00:04:26,280 are expecting this kind of thing 110 00:04:26,280 --> 00:04:28,440 and they could care less how we wanna sort something 111 00:04:28,440 --> 00:04:30,000 or how we wanna compare something, 112 00:04:30,000 --> 00:04:31,920 that's for our logic determine. 113 00:04:31,920 --> 00:04:32,880 Try one more. 114 00:04:32,880 --> 00:04:34,950 Oh, and by the way, I should mention 115 00:04:34,950 --> 00:04:37,890 this line 95 right here, 116 00:04:37,890 --> 00:04:42,210 we use this in C++ 14 or higher. 117 00:04:42,210 --> 00:04:46,620 In C++ 20, we can replace this 118 00:04:46,620 --> 00:04:49,530 with just this, auto func 119 00:04:49,530 --> 00:04:52,740 and let the compiler figure out that it returns a boolean 120 00:04:52,740 --> 00:04:54,000 and expects an initial parameter. 121 00:04:54,000 --> 00:04:55,290 So that's pretty cool too. 122 00:04:55,290 --> 00:04:57,930 But that's would, that would be a C++ 20. 123 00:04:57,930 --> 00:04:59,553 Lemme scroll this up as well. 124 00:05:01,110 --> 00:05:03,330 Okay, so now we're in test five 125 00:05:03,330 --> 00:05:05,430 and it's these two pieces right here. 126 00:05:05,430 --> 00:05:07,410 All right, so what's going on in test five? 127 00:05:07,410 --> 00:05:09,990 Well, test five is a little bit different as well. 128 00:05:09,990 --> 00:05:11,790 And you'll see this make more sense 129 00:05:11,790 --> 00:05:13,590 when we talk about stateful lambdas 130 00:05:13,590 --> 00:05:15,240 in the next couple of sections. 131 00:05:15,240 --> 00:05:16,620 But in this case, look what I've got. 132 00:05:16,620 --> 00:05:20,070 I've got a function called make lambda 133 00:05:20,070 --> 00:05:22,830 and what does it return? Auto. 134 00:05:22,830 --> 00:05:25,110 Let the compiler figure it out. 135 00:05:25,110 --> 00:05:26,400 It's returning a lambda. 136 00:05:26,400 --> 00:05:27,570 You can see right here, right? 137 00:05:27,570 --> 00:05:31,200 It's return, there's my capture list, no parameters 138 00:05:31,200 --> 00:05:34,020 and there's the body of the lambda, a sea of statement. 139 00:05:34,020 --> 00:05:35,550 Wow, you know you wrap your head around this thing 140 00:05:35,550 --> 00:05:37,260 and you're going, well what's going on here? 141 00:05:37,260 --> 00:05:41,040 Well I'm calling a function that's returning a lambda. 142 00:05:41,040 --> 00:05:42,600 It's not executing that lambda. 143 00:05:42,600 --> 00:05:44,130 It's just returning the lambda. 144 00:05:44,130 --> 00:05:46,590 Later on I can execute that lambda if I want. 145 00:05:46,590 --> 00:05:48,270 And that's what I'm doing right here. 146 00:05:48,270 --> 00:05:52,530 You can see right here I'm displaying test five right there. 147 00:05:52,530 --> 00:05:54,303 Then I'm calling make_lambda, 148 00:05:55,320 --> 00:05:56,670 that's my function 149 00:05:56,670 --> 00:05:58,620 and I'm assigning whatever it's returning, 150 00:05:58,620 --> 00:06:00,660 which is a lambda in this case, 151 00:06:00,660 --> 00:06:03,750 to this lambda right here called L5 152 00:06:03,750 --> 00:06:05,370 and now I'm calling it. 153 00:06:05,370 --> 00:06:08,310 And when I call it, it instantiates the lambda, 154 00:06:08,310 --> 00:06:10,380 executes that lambda that's being returned 155 00:06:10,380 --> 00:06:12,060 and you could see what displays. 156 00:06:12,060 --> 00:06:14,430 This lambda was made using make_lambda. 157 00:06:14,430 --> 00:06:15,720 We could pass parameters. 158 00:06:15,720 --> 00:06:17,820 We could do all kinds of things and again, 159 00:06:17,820 --> 00:06:21,570 it makes more sense to see this in the stateful context. 160 00:06:21,570 --> 00:06:24,750 So I'll leave those examples for the next couple of videos. 161 00:06:24,750 --> 00:06:26,310 But you can see it's pretty cool, right? 162 00:06:26,310 --> 00:06:28,560 That a lambda, that sorry that a function 163 00:06:28,560 --> 00:06:29,670 can return a lambda 164 00:06:29,670 --> 00:06:31,230 and those lambdas that we return 165 00:06:31,230 --> 00:06:33,390 can be pretty complicated as well. 166 00:06:33,390 --> 00:06:35,130 Let's move over to test six 167 00:06:35,130 --> 00:06:38,580 and there's just a couple left, couple of examples. 168 00:06:38,580 --> 00:06:41,610 And this one's a pretty easy example to understand 169 00:06:41,610 --> 00:06:44,910 and we're over here in test six. 170 00:06:44,910 --> 00:06:45,780 So what do we do here? 171 00:06:45,780 --> 00:06:48,690 Well this is using auto in the lambda parameter list. 172 00:06:48,690 --> 00:06:51,510 I mentioned this in the slides in the previous lecture. 173 00:06:51,510 --> 00:06:54,330 Notice now I'm saying auto and auto. 174 00:06:54,330 --> 00:06:56,100 So I'm telling the compiler, hey compiler 175 00:06:56,100 --> 00:06:58,050 you figure out what's going on. 176 00:06:58,050 --> 00:07:00,360 This is pretty cool because we're not to having to create 177 00:07:00,360 --> 00:07:02,130 some generic template function here. 178 00:07:02,130 --> 00:07:03,510 We're just doing it this way. 179 00:07:03,510 --> 00:07:06,900 So again, L6 is the variable. 180 00:07:06,900 --> 00:07:09,510 Let the compiler figure out the type 181 00:07:09,510 --> 00:07:12,480 and what are we assigning to this variable? A lambda. 182 00:07:12,480 --> 00:07:14,880 No capture, two parameters. 183 00:07:14,880 --> 00:07:15,990 What are their types? 184 00:07:15,990 --> 00:07:16,823 I don't know. 185 00:07:16,823 --> 00:07:18,690 Let the compiler figure it out. 186 00:07:18,690 --> 00:07:20,520 And within the body of that lambda, 187 00:07:20,520 --> 00:07:22,890 all we're doing is we're displaying X 188 00:07:22,890 --> 00:07:24,300 and we're displaying Y. 189 00:07:24,300 --> 00:07:27,060 What's the type of X and Y? Again I don't know. 190 00:07:27,060 --> 00:07:28,740 The compiler will figure it out. 191 00:07:28,740 --> 00:07:31,200 So now that I've got my lambda, 192 00:07:31,200 --> 00:07:34,680 my lambda expression in the variable L6, I can call it. 193 00:07:34,680 --> 00:07:36,720 Right here, I'm calling it with two integers. 194 00:07:36,720 --> 00:07:38,580 So the compiler sees this and says 195 00:07:38,580 --> 00:07:39,413 oh, that's an int. 196 00:07:39,413 --> 00:07:41,280 That's an int. Aha, int int. 197 00:07:41,280 --> 00:07:42,990 10 20 is being displayed. 198 00:07:42,990 --> 00:07:43,950 Now I'm displaying it. 199 00:07:43,950 --> 00:07:46,470 I'm calling it with a double and an integer. 200 00:07:46,470 --> 00:07:49,590 So it's displaying 100.3 and 200, right? 201 00:07:49,590 --> 00:07:51,060 The double and the integer. 202 00:07:51,060 --> 00:07:52,680 Here's two doubles. 203 00:07:52,680 --> 00:07:54,030 That works too. 204 00:07:54,030 --> 00:07:55,560 But this is where it's really neat. 205 00:07:55,560 --> 00:07:57,300 I'm calling L6 now 206 00:07:57,300 --> 00:08:00,900 and I'm passing in two person objects: 207 00:08:00,900 --> 00:08:03,810 Larry 18, Curly 22. 208 00:08:03,810 --> 00:08:05,730 These guys, the compiler's gonna say 209 00:08:05,730 --> 00:08:06,990 oh those are person objects. 210 00:08:06,990 --> 00:08:08,910 Remember I created that person class 211 00:08:08,910 --> 00:08:10,920 up at the top of this file. 212 00:08:10,920 --> 00:08:14,550 So it's gonna pass those things into this lambda, 213 00:08:14,550 --> 00:08:15,960 execute the lambda 214 00:08:15,960 --> 00:08:20,960 and it's gonna display person Larry 18, person Curly 22. 215 00:08:21,600 --> 00:08:23,103 Same thing we passed in here. 216 00:08:24,240 --> 00:08:25,980 Now that's pretty cool. 217 00:08:25,980 --> 00:08:28,473 Now a couple of things that are happening here. 218 00:08:29,460 --> 00:08:33,539 It's very important that whatever you pass into this 219 00:08:33,539 --> 00:08:36,030 must overload this operator, right? 220 00:08:36,030 --> 00:08:37,409 I mean we're displaying these guys 221 00:08:37,409 --> 00:08:39,600 using this operator right here. 222 00:08:39,600 --> 00:08:42,270 I've already, I have overloaded the insertion operator 223 00:08:42,270 --> 00:08:45,510 in that person class that I've already created up there. 224 00:08:45,510 --> 00:08:47,070 So this is really important. 225 00:08:47,070 --> 00:08:48,630 Otherwise you're gonna get a compiler error 226 00:08:48,630 --> 00:08:50,760 that may not be too easy to read 227 00:08:50,760 --> 00:08:52,830 and it's gonna say something about operator 228 00:08:52,830 --> 00:08:55,860 less than less than not defined somehow. 229 00:08:55,860 --> 00:08:56,970 It's not a problem here 230 00:08:56,970 --> 00:08:58,920 because the floats and the ints and the doubles 231 00:08:58,920 --> 00:09:02,640 all support the overloaded insertion operator. 232 00:09:02,640 --> 00:09:06,300 Last example, this example right here is test seven. 233 00:09:06,300 --> 00:09:08,400 Also really straightforward example. 234 00:09:08,400 --> 00:09:09,480 What we're doing here 235 00:09:09,480 --> 00:09:10,890 and lemme scroll this up just a little 236 00:09:10,890 --> 00:09:12,390 so we can see it a little bit better. 237 00:09:12,390 --> 00:09:15,120 I'm right here in test seven. 238 00:09:15,120 --> 00:09:17,400 What I've done is I've created a vector 239 00:09:17,400 --> 00:09:20,220 of person objects called stooges. 240 00:09:20,220 --> 00:09:21,690 So there are Larry, Mo and Curly. 241 00:09:21,690 --> 00:09:24,660 Larry's 18, Mo is 30, Curly's 25. 242 00:09:24,660 --> 00:09:25,493 Now what I'm doing 243 00:09:25,493 --> 00:09:28,170 is I'm calling some of the standard template library 244 00:09:28,170 --> 00:09:30,930 algorithm functions. Okay, I'm gonna use two of them. 245 00:09:30,930 --> 00:09:34,560 I'm gonna use std sort and std for each. 246 00:09:34,560 --> 00:09:38,520 They take in lambda expressions or function objects. 247 00:09:38,520 --> 00:09:40,230 In this case I'm using lambdas. 248 00:09:40,230 --> 00:09:43,620 So I'm calling std sort 249 00:09:43,620 --> 00:09:46,350 and basically it says, well what do you want to sort? 250 00:09:46,350 --> 00:09:48,000 Where does it start? Where does it end? 251 00:09:48,000 --> 00:09:50,850 So begin stooges, end stooges, right? 252 00:09:50,850 --> 00:09:52,320 There's my vector. 253 00:09:52,320 --> 00:09:54,420 I wanna start at the beginning, go to the end. 254 00:09:54,420 --> 00:09:58,060 Remember this is just an alternate syntax for stooges 255 00:09:59,197 --> 00:10:01,710 .begin and .end. 256 00:10:01,710 --> 00:10:03,720 We can do it like begin like this or like this. 257 00:10:03,720 --> 00:10:05,010 Either way it works. 258 00:10:05,010 --> 00:10:06,963 And here is the lambda expression. 259 00:10:08,100 --> 00:10:10,920 Remember std sort is expecting a function object. 260 00:10:10,920 --> 00:10:13,290 So that's why I'm gonna send it. 261 00:10:13,290 --> 00:10:15,000 No capture list, 262 00:10:15,000 --> 00:10:19,080 two parameters by const reference. 263 00:10:19,080 --> 00:10:21,300 The first one is one person, 264 00:10:21,300 --> 00:10:22,680 the other is the other person. 265 00:10:22,680 --> 00:10:23,610 It's sorting. 266 00:10:23,610 --> 00:10:26,010 So when you're sorting, you're comparing two things 267 00:10:26,010 --> 00:10:27,390 and moving them around. 268 00:10:27,390 --> 00:10:31,410 Well how does this guy know where to move things around? 269 00:10:31,410 --> 00:10:33,510 Well you need to tell it which one is bigger. 270 00:10:33,510 --> 00:10:38,190 So in this case, I'm returning P1 get the name 271 00:10:38,190 --> 00:10:40,830 and if it's less than P2's name, 272 00:10:40,830 --> 00:10:44,040 I'm gonna return true or false depending on this condition. 273 00:10:44,040 --> 00:10:45,750 Based on that condition, 274 00:10:45,750 --> 00:10:48,450 the std sort algorithm knows which one is greater, 275 00:10:48,450 --> 00:10:51,090 which one is less than and it can do what its thing. 276 00:10:51,090 --> 00:10:52,350 Now this is pretty powerful. 277 00:10:52,350 --> 00:10:55,380 This is again a predicate lambda right here. 278 00:10:55,380 --> 00:10:58,230 You can see that this is a predicate lambda right here. 279 00:10:58,230 --> 00:11:00,570 We're passing in some parameters 280 00:11:00,570 --> 00:11:03,000 and it's returning a boolean. 281 00:11:03,000 --> 00:11:04,710 So that's exactly what's happening here 282 00:11:04,710 --> 00:11:07,200 and that's exactly what std sort expects. 283 00:11:07,200 --> 00:11:08,550 So what's going on? 284 00:11:08,550 --> 00:11:13,080 I'm sorting the stooges vector by name. 285 00:11:13,080 --> 00:11:15,960 Now when I finish this, 286 00:11:15,960 --> 00:11:18,510 this std vector right here will be sorted. 287 00:11:18,510 --> 00:11:21,090 Now I just want to display each element in there. 288 00:11:21,090 --> 00:11:22,140 And to do that, I'm gonna use 289 00:11:22,140 --> 00:11:25,683 another standard template library algorithm called for_each. 290 00:11:27,150 --> 00:11:28,110 Now what does this do? 291 00:11:28,110 --> 00:11:29,730 Well, where do you wanna start? 292 00:11:29,730 --> 00:11:33,120 Where do you wanna end and what do you want to do? 293 00:11:33,120 --> 00:11:36,240 So it's gonna loop through that vector. 294 00:11:36,240 --> 00:11:38,850 That's what it's doing for each element in the vector. 295 00:11:38,850 --> 00:11:40,290 it's gonna loop through that vector 296 00:11:40,290 --> 00:11:42,270 and for each one of those elements, 297 00:11:42,270 --> 00:11:45,123 it's going to call this lambda function right here. 298 00:11:46,170 --> 00:11:48,120 It's gonna take that element in here, 299 00:11:48,120 --> 00:11:49,320 Larry, Mo, Curly, 300 00:11:49,320 --> 00:11:51,810 pass it into here and I'm just gonna display it. 301 00:11:51,810 --> 00:11:54,453 So when I call this, look what happened right here. 302 00:11:57,150 --> 00:11:58,470 Curly, Larry, Mo. 303 00:11:58,470 --> 00:12:02,100 Notice it's sorted alphabetically, C-L-M, right? 304 00:12:02,100 --> 00:12:03,840 Curly, Larry, Mo. 305 00:12:03,840 --> 00:12:06,480 It used to be Larry, Mo, Curly. 306 00:12:06,480 --> 00:12:09,360 So this function right here that we called 307 00:12:09,360 --> 00:12:11,490 absolutely sorted that vector 308 00:12:11,490 --> 00:12:15,000 based on the condition in our predicate lambda. 309 00:12:15,000 --> 00:12:18,570 all right, so one more example and we're right here now. 310 00:12:18,570 --> 00:12:20,940 I'm calling std sort again. 311 00:12:20,940 --> 00:12:23,640 This time I'm sorting based on age. 312 00:12:23,640 --> 00:12:25,410 I wanna sort based on age. 313 00:12:25,410 --> 00:12:26,370 Same idea, right? 314 00:12:26,370 --> 00:12:27,930 Gimme the two parameters 315 00:12:27,930 --> 00:12:31,710 and return P1's age less than P2's age. 316 00:12:31,710 --> 00:12:33,527 Now std sort knows 317 00:12:33,527 --> 00:12:35,430 you know which one to put ahead of the other. 318 00:12:35,430 --> 00:12:36,720 And once we do that, 319 00:12:36,720 --> 00:12:38,670 we're gonna do this std for each again. 320 00:12:38,670 --> 00:12:41,370 And this code and this code are exactly the same. 321 00:12:41,370 --> 00:12:43,560 But look what happens over here. 322 00:12:43,560 --> 00:12:46,740 Now we're gonna display Larry, Curly and Mo 323 00:12:46,740 --> 00:12:49,050 but now they're sorted by age. 324 00:12:49,050 --> 00:12:49,883 There you go. 325 00:12:49,883 --> 00:12:52,170 This gives you a, I think a pretty good introduction 326 00:12:52,170 --> 00:12:54,420 to different kinds of stateless lambdas 327 00:12:54,420 --> 00:12:57,870 using references, by value, objects and so forth. 328 00:12:57,870 --> 00:12:59,580 In the next video, we'll switch over 329 00:12:59,580 --> 00:13:03,150 and we'll start talking about stateful lambda expressions. 330 00:13:03,150 --> 00:13:04,550 So I'll see you in that one.