0

Map of custom class as key without < or > operator

Hi I am aware that key must be comparable for map. So, we need atleast < operator in class to have class as key of map. Refer code below and Test1 class is doing same. I was asked for other alternative and then I gave > operator. Same is there as Test2 class in code. Another approach is having < or > operator as global function rather than class members. I was asked further. Is there any other mechanism to achieve class as key for map? https://sololearn.com/compiler-playground/cIsvZgIltQE6/?ref=app

30th Sep 2024, 3:48 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 1
alternatively, you can use function object: https://sololearn.com/compiler-playground/cA3H8x4Uartp/?ref=app
2nd Oct 2024, 12:10 PM
MO ELomari
MO ELomari - avatar
+ 1
Thanks MO ELomari . I got another hint also in terms of generic function to print the map.
2nd Oct 2024, 12:41 PM
Ketan Lalcheta
Ketan Lalcheta - avatar