title: What is this third parameter in sort function of c++?
body: <p>It seems to be something related to comparators, what does each thing in it mean?
  First of all, I would like to add, I don't really understand comparators, something I'll look into when I can but, that aside, I see this kind of syntax many times, and even though I have some idea what it means, I would like someone to provide a detailed answer or resource for this.</p>
  
  <p>1.
  What is the first <code>[]</code>, I have seen it as <code>[&amp;]</code> also how is that different?
  The next <code>(const int a, const int b)</code> I suppose are parameters to a unnamed function, which we declared and are using on the fly? and <code>{return to_string(a) + to_string(b) &gt; to_string(b) + to_string(a);}</code> is the body, how do we know it's return type is bool?</p>
  
  <ol start="2">
  <li>Second one seems even more confusing to me, it's converting int to string and and accumulating the result in it. What is the use of <code>move()</code> here? if we just wrote return <code>s + to_string(i)</code> wont that be same too? after all the string s is passed by reference? But more importantly it's not a comparator I think? So then what exactly is it?</li>
  </ol>
  
  <p>I understand I have some gaps in my knowledge and won't be able to understand fully but I can't seem to find this on the internet (maybe I don't know the right terms to search) so it would probably be helpful for others too.</p>
  
  <p>Code
   1:</p>
  
  <pre><code>sort(nums.begin(), nums.end(), [](const int a, const int b) { return to_string(a) + to_string(b) &gt; to_string(b) + to_string(a);});
  </code></pre>
  
  <p>Code 2:</p>
  
  <pre><code>return accumulate(nums.begin(), nums.end(), string(""), [](string&amp; s, int i){ return move(s) + to_string(i);}) ;
   }
  </code></pre>