I'm trying to create a class that represents a bucket of locks, and I
want to lock a set of objects specified by a container of pointers. I
can't seem to find the right combination of function adapters to invoke
the bucket's member function on each pointer in the argument container.
What's the right thing to use here, at the "???"?
#include <vector>
#include <functional>
#include <algorithm>
using namespace std; // keeps example simple
class BucketOfLocks;
class Lockable
{
BucketOfLocks* owner;
public:
void acquire(BucketOfLocks& newOwner) { owner = &newOwner; }
};
class BucketOfLocks
{
public:
BucketOfLocks(const vector<Lockable*>& lockables);
private:
// this is what I want to invoke in the for_each
void acquire(Lockable& lockable);
};
BucketOfLocks::BucketOfLocks(const vector<Lockable*>& lockables)
{
for_each(lockables.begin(), lockables.end(),
???(&BucketOfLocks::acquire,*this));
}