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?
Asked
Active
Viewed 75 times
1

Akhil Shukla
- 61
- 6
-
6Your 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