I want to sort a vector vec containing int iterators pointing to elements in another vector int_vec. I want to use the following compare function: it1 < it2 if and only if
index[it1 - int_vec.begin()] < index[it2 - int_vec.begin()].
Where index is a third vector specifying the key of an iterator. Now the vector index is an internal array of the constructor of A and int_vec is a member variable of a class A. I tried to just pass an anonymous function like this:
std::sort(vec.begin(),flow.end(), [&index,&edges](const int_iter it1 ,const int_iter it2) -> bool
{
index[it1 - int_vec.begin()] < index[it2 - int_vec.begin()];
})
but I get an error telling me that member objects cannot be captured. Exact error message is:
'this' cannot be implicitly captured in this context
index[it1 - int_vec.begin()] < index[it2 - int_vec.begin()];.
I also tried to just declare an external compare function but it is not clear to me how I can bind two fixed values to it(I read about boost::bind which looks like solving exactly this but I would prefer to not download additional libraries).