Sorting vector based on tuple value
<p>I have below data structure, </p>

<pre><code>typedef vector&lt; tuple&lt;int,int,int&gt; &gt; vector_tuple;
</code></pre>

<p>In vector i am storing <code>tuple&lt;value,count,position&gt;</code></p>

<p>I want to sort my vector based on count, If count is same then based on position sort the vector.</p>

<pre><code>structure ordering
{
  bool ordering()(....)
  {
    return /// ?
  }

};
int main()
{ 
    std::vector&lt;int&gt; v1{1,1,1,6,6,5,4,4,5,5,5};
    std::vector&lt;int&gt; v2(v1);
    vector_tuple vt;
    std::tuple&lt;int,int,int&gt; t1;
    std::vector&lt;int&gt;::iterator iter;
    int sizev=v1.size();
    for(int i=0; i &lt; sizev ; i++)
    {
         auto countnu = count(begin(v2),end(v2),v1[i]);  
         if(countnu &gt; 0)
         {
           v2.erase(std::remove(begin(v2),end(v2),v1[i]),end(v2));
           auto t = std::make_tuple(v1[i], countnu, i);
           vt.push_back(t);
         }
     }
     sort(begin(vt),end(vt),ordering(get&lt;1&gt;vt); // I need to sort based on count and if count is same, sort based on position.


     for (int i=0; i &lt; vt.size(); i++)
     {

        cout &lt;&lt; get&lt;0&gt;(vt[i]) &lt;&lt; " " ;
        cout &lt;&lt; get&lt;1&gt;(vt[i]) &lt;&lt; " " ;
        cout &lt;&lt; get&lt;2&gt;(vt[i]) &lt;&lt; " \n" ;
     }

}
</code></pre>