1

We do not change the value of the variables in the comparator function only compare or read it. So what is the need of adding const in the comparator? Is it a good programming habit or there is some other reason?

  • 6
    Your first sentence is *exactly* the reason why a member comparator is `const`. The const-ness enforces your "do not" to be "cannot", which is critical . Thou shalt not modify a sequence whilst being mangled by canned `sort`; that's the job for `sort`; not you. – WhozCraig Jul 02 '21 at 07:34
  • Yeah, it answers them, Paul. Thank you, guys. – Akhil Shukla Jul 02 '21 at 08:01

0 Answers0