Filtering the condition and implementing a Lambda expression

Let's focus on the GetActiveCustomerByFunctionField() method. There, we can find an if structure to filter the active customer. As we discussed in the previous chapters, we can use the copy_if() method to filter the condition. The following code snippet implements the copy_if() method to filter the active customer:

    template<typename T>    vector<T> Customer::GetActiveCustomerByFunctionField(      vector<Customer> customers,      const shared_ptr<BaseClass<Customer, T>>        &classField)        {          vector<Customer> activeCustomers;          vector<T> returnList;          copy_if(            customers.begin(),            customers.end(),            back_inserter(activeCustomers),            [](Customer customer)            {             if (customer.isActive)                return true;             else return false; ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.