C++ equivalent for passing a lambda function as an argument in python
<p>In python you can just pass a lambda function as an argument, like the following:</p>

<pre><code>class Thing(object):
    def __init__(self, a1, a2):
        self.attr1 = a1
        self.attr2 = a2

class ThingList(object):
    def __init__(self):
        self.things = [Thing(1,2), Thing(3,4), Thing(1,4)]

    def getThingsByCondition(self, condition):
        thingsFound = []
        for thing in self.things:
            if condition(thing):
                thingsFound.append(thing)
        return thingsFound

things = tl.getThingsByCondition(lambda thing: thing.attr1==1)
print things
</code></pre>

<p>Is there a way to do something similar in C++? I need to do this because I want to search a <code>vector</code> of objects for objects fulfilling certain criteria.</p>

<hr>

<p>Okay, I tried to solve it like this:
I should mention that the "things" I'm managing in a vector are employees and I want to find Employees fulfilling certain conditions.</p>

<pre><code>employee_vector getEmployeeByCondition(function&lt;bool(const Employee&amp;)&gt; condition) {
    employee_vector foundEmployees;
    for (int i = 0; i &lt; employees.size(); i++) {
        Employee e = employees.at(i);
        if (condition(e)) {
            foundEmployees.push_back(e);
        }
    }
    return foundEmployees;
}

employee_vector getEmployeeByBirthday(Date bday) {
    employee_vector found;
    found = getEmployeeByCondition([](Employee e) {return e.birthday == bday;});
    return found;
}
</code></pre>

<p>Now the problem is that I obviously can not use <code>bday</code> in the lambda function in <code>getEmployeeByBirthday</code>, as it is a local variable.</p>