From the course: Introducing Functional Programming in C++

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

copy_if instead of filter

copy_if instead of filter - C++ Tutorial

From the course: Introducing Functional Programming in C++

Start my 1-month free trial

copy_if instead of filter

- [Instructor] So let's go ahead and create our copy_if. So first thing we want to do is get a little bit of space. We're going to create another vector. It's going to be of int, and we'll call this filteredCollection. We're going to use back_inserter on it, so we don't need to initialize it with any data, and we're going to have our copy_if, and it takes an outCollection.begin, which is our begin iterator. Then we're going to have outCollection.end. There's our end iterator, and we'll go ahead and put this on the next line. We'll scroll up a little bit, just give ourselves a little bit more room. Then we're going to have a back_inserter, back underscore inserter, and this is going to take our filteredCollection, and finally, we'll have our lambda, and our lambda is going to be open, close square brackets, parentheses, and we have an int, reference to a value, and then open and close curly braces, and inside of here, we will have a return, and it will do a value, modulus two, not…

Contents