C++ Sort vector of <T> according to vector of double
<p>I want to sort a vector of T according to a vector of double. That is, if I have</p>

<pre><code>vector&lt;T&gt; a;
vector&lt;double&gt;b;
</code></pre>

<p>If <code>a</code> is <code>{t1, t2, t3, t4}</code> and <code>b</code> is <code>{3, 1, 5, 2}</code>, I want to obtain <code>{t2, t4, t1, t3}</code>.</p>

<p>I don't know how to declare the template. I'm trying something like</p>

<pre><code>template&lt;vector&lt;class T&gt;&gt; vector&lt;T&gt; sortByArray(vector&lt;T&gt; a, vector&lt;double&gt;b)
</code></pre>

<p>And I don't have any idea of how to write the function body either.</p>

<p>Thanks.</p>

<p>EDIT: This is the usage of my algorithm. I don't get it right.</p>

<pre><code>template &lt;typename T&gt; struct dataPair
{
    dataPair(double s, T o) 
    : m_sortData(s)
    , m_otherData(o)
    {

    }

    bool operator&lt; (const dataPair &amp;rhs) { return (m_sortData &lt; rhs.m_sortData); }

    double m_sortData;
    T m_otherData;

}



  template &lt;class T&gt; vector&lt;T&gt; sortByArrayStuff(vector&lt;T&gt; objects, vector&lt;double&gt; sortNumber) {
    vector&lt;dataPair&lt;T&gt;&gt; v;
    for (unsigned int i = 0; i &lt; objects.size(); i++) {
        v.push_back(dataPair&lt;T&gt;(objects[i], sortNumber[i]));
    }
    sort(v.begin(), v.end());
    vector&lt;T&gt; retVal;

    for (unsigned int i = 0; i &lt; objects.size(); i++) {
        retVal.push_back(dataPair&lt;T&gt;(objects[i], sortNumber[i]));
    }
    return retVal;
};
</code></pre>

<p>I want to use the same template for vectors of "Points" and vectors of vectors of "Points":</p>

<pre><code>vector&lt;double&gt; sortedAreas;
vector&lt;Point&gt; sortedPoints = sortByArray&lt;vector&lt;Point&gt;&gt;(points, sortedAreas);
vector&lt;vector&lt;Point&gt;&gt; sortedContours = sortByArray&lt;vector&lt;vector&lt;Point&gt;&gt;&gt;(contours, sortedAreas);
</code></pre>

<p>Error is</p>

<pre><code>cannot convert parameter 1 from 'dataPair&lt;T&gt;' to 'cv::Point &amp;&amp;'
          with
          [
              _Ty=cv::Point
          ]
          and
          [
              T=cv::Point
          ]
          Reason: cannot convert from 'dataPair&lt;T&gt;' to 'cv::Point'
          with
          [
              T=cv::Point
          ]
</code></pre>
