title: Sorting a std::vector of std::pair's using user defined compare class
body: <p>I have two class templates <code>MyClassA&lt;T&gt;</code> and <code>MyClassB&lt;T&gt;</code>.</p>
  
  <p>From these, I have constructed two <code>std::vector</code>'s as <code>std::vector&lt;MyClassA&lt;double&gt;&gt; A</code> and <code>std::vector&lt;MyClassB&lt;double&gt;&gt; B</code>.</p>
  
  <p>My goal is to first sort <code>A</code> in ascending order (in actual I will do a range/partial sort). </p>
  
  <p>Then using that order to sort <code>B</code>.</p>
  
  <p>What I am doing so far is the following:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;functional&gt;
  #include &lt;random&gt;
  
  // my class definitions
  template&lt;typename T&gt;
  class MyClassA
  {
  public:
      T valA;
  };
  
  template&lt;typename T&gt;
  class MyClassB
  {
  public:
      T valB;
  };
  
  // my compare class
  template&lt;typename T&gt;
  using TIter = typename std::vector&lt;T&gt;::const_iterator;
  
  template &lt;typename T&gt;
  class MyCompare
  {
  public:
      bool operator()(std::pair&lt;std::size_t, TIter&lt;MyClassA&lt;T&gt;&gt;&gt;
             const&amp; a, std::pair&lt;std::size_t, TIter&lt;MyClassA&lt;T&gt;&gt;&gt; const&amp; b)
      {
          return *(a.second).valA &lt; *(b.second).valA;
      }
  };
  
  // sort from given order
  //... not yet implemented
  
  int main()
  {
      std::random_device rd;
      std::mt19937 gen(rd());
      std::uniform_real_distribution&lt;&gt; dis(0, 1);
  
      // first ClassA Object vector A
      std::vector&lt;MyClassA&lt;double&gt;&gt; A(5);
      for(auto&amp; i:A) i.valA = dis(gen);
      // second ClassB Object vector B
      std::vector&lt;MyClassB&lt;double&gt;&gt; B(5);
      for(auto&amp; i:B) i.valB = dis(gen);
  
      // sort vector A elements' references in ascending order
      std::size_t i = 0;
      std::vector&lt;std::pair&lt;std::size_t, TIter&lt;MyClassA&lt;double&gt;&gt;&gt;&gt; torder(A.size());
      for(auto it = A.begin(); it != A.end(); ++it, ++i) torder[i] = std::make_pair(i, it);
      std::sort(torder.begin(), torder.end(), MyCompare&lt;double&gt;()); // getting error here
  
      // sort vectors A and B elements using the above sorted order
      // ...
      return 0;
  }
  </code></pre>
  
  <p>However, I am getting the following error:</p>
  
  <p><code>error: 'const class __gnu_cxx::__normal_iterator&lt;const MyClassA&lt;double&gt;*, std::vector&lt;MyClassA&lt;double&gt; &gt; &gt;' has no member named 'valA'</code></p>