title: sorting iterators with std::sort
body: <p>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 &lt; it2 if and only if </p>
  
  <pre><code>index[it1 - int_vec.begin()] &lt; index[it2 - int_vec.begin()]. 
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>std::sort(vec.begin(),flow.end(), [&amp;index,&amp;edges](const int_iter it1 ,const int_iter it2) -&gt; bool
  { 
      index[it1 - int_vec.begin()] &lt; index[it2 - int_vec.begin()]; 
  })
  </code></pre>
  
  <p>but I get an error telling me that member objects cannot be captured. Exact error message is: </p>
  
  <pre><code>'this' cannot be implicitly captured in this context
          index[it1 - int_vec.begin()] &lt; index[it2 - int_vec.begin()];.
  </code></pre>
  
  <p>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). </p>