 Hey everybody, this is Brian. Welcome to the 127th Qtutorial with C++ and GUI programming. We are fastly approaching that 150 mark. Wow. I'm going to think of something special for 150. Something special that's not going to take me two years to do, but all right, so we're going to do future reduce. This one is a little bit tricky. I think we can get there though. I think we've learned enough that we can figure this out. The first thing I'm going to do is not make the mistakes of the past. I'm going to add in the concurrent library right away, and we're going to add in our... I have to go grab Christmas presents after this. It's Christmas Eve and I've been kind of like on a tutorial marathon just because I'm really procrastinating wrapping presents. I love buying them. I love giving other people things. I'm very charitable. At least I think I am, but I really just dislike wrapping presents. There should be a law that I'm not allowed to do it just because I'm horrible at it. All right, so we're going to say filter reduce. Now, if you pay attention during our map reduce, you kind of have an understanding of what's going to happen here. Maybe if I can get my mouse to agree with me. All right, so we need two functors or two functions as they're called. One to actually filter and one to do the reduction. A filter will actually filter things out of our sequence or our list and the reductor will actually collapse the list down into a single item. That's kind of confusing, isn't it? Well, let's dive right in. Static, bowl. And we're going to call this do filter. And we're going to stay kind of with the same principles we've been doing so we don't really have to get confused with names and things. Static and we're going to say void do reduce. And we're going to say a queue string result. And then we want the const string, oops, queue string item. There we go. Now, the signatures for these are actually pretty simple. The filter, we're just giving it a queue string of a name and we're going to return a boolean. The reduce, we're not going to actually return anything but we have a reference to this result which is going to be the end product of all of our work. And then we have the individual item that's being reduced. Let's actually jump through here. Alright, so you've been following along. You know there's going to be pretty simple little code in here. So we're going to say if name to lower. Yep, we're going to pick on Bob again just because Bob just drives me nuts at work and return false. Otherwise, oops, we're going to actually return something here. There we go. That would have been embarrassing again. Alright, now our reductor is we're going to actually just take the result and we're going to say plus equals, oops, plus equals, I need a new keyboard. That might be a Christmas present to myself as a new keyboard. I need a new keyboard. Anyhow, so we're just going to do that. So we're just going to basically concatenate that string. And we should by all rights do the result dot append, but just for the sake of argument, let's leave it like that. Key string list, people, pupil, people. There we go. Yes, I'm going to blame my keyboard for my horrible spelling. There we go. And we're going to say Heather, Bob, Bob's got to be in there. Mark and let's do someone new Natalie. Okay, same principle. We're going to click the button. You'll see the old and the new just so you can see the difference here. We're going to actually jump back in here. And we are going to actually introduce the Q future class here today. And we're going to say Q string that tells you right off the bat. It's a template class. We're going to call it reduced equals. And we're going to say Q concurrent. And instead of the blocking, we're going to do the filtered reduced. This is going to take a little bit of explaining, but we can do it. You can see the definition of this thing goes right off the screen. So what we need to do here is we need to hand up the sequence, which in this case is people. We need to then hand it the filter functor, which is a function pointer to do filter. And then we need to give it the reductor functor. I like that word functor. I want to go home and get functor tonight. That didn't sound good. Just let's just pretend I never said that. All right, and then we're say do reduce. And there's other options that you can add in at the end, but we're just going to leave things as the default. Now, if we run this as is, what's going to happen? Well, bad things are going to happen. And I actually did that wrong, didn't I? Yes, I did. Hmm. Yeah, let's change this up a little bit. I don't want that. I'm just kind of kind of going to change things up here. I'm getting sick of that. Let's do the line edit. Let's do this move line edit. There you go. Because I mean, the point of a reduction is to reduce it from a bunch of items down to one. So this will be a clear example. Alright, let's actually get rid of that, let's say. So if we run this as is, well, first off, it won't display anything, but we'll say Q string. Oops, not Q string. Let's go UI, line edit, set text. And we could say reduced result. If we run that, it's not going to work the way you think it's going to work. Because remember, we were doing blocking and blocking will actually stop execution of the program. So as you've probably guessed, because you're pretty bright at this point, it's just going to jump immediately to this. So it may or may not actually work on mine. It worked, but we're going to clear this example up a little bit better. UI, let's widget. Oops, let's widget add items, say people. We're going to clear this up a little better and do it the proper way. First thing we need to do is actually wait for that reduced wait for finished. And if you haven't guessed the blocking filtered and blocking mapped actually just calls this under the hood. So we're going to wait for it to finish. And then we're going to actually just grab this guy and through the what I like to call the magic of copy and paste, we're going to say Q string result equals the reduced result. And then we're just going to result chop. If you don't know what chop does, it just removes X number of characters off the end of a string. All right, so we're doing that because every item is going to have that comment in. Let's run this bad boy. And Bob is not in our list of people. So that's what filter reduce does it filters it. We took Bob out of there and it reduces it or collapses it down to a single item. If you're kind of wondering some practical uses for that cryptography, like creating a hash, something of that nature could actually be done. Building a common delimited list of files or building like a number of files that are over or under a certain size, things like that. So that is the filter reduce. And we've also introduced the Q future, which we're going to be working with in future tutorials that just bog that bugs me that I say future future tutorials. I just I don't know why. All right, be sure to visit my website void realms.com for source code for this and other tutorials. Also be sure to visit my pet project plug in bot net. And we do have a Facebook group called void realms. There's like 130 some odd of you guys and girls out there. And we just kind of ask each other questions. We all kind of work as a team to help each other out. That's it. Thanks for watching.