0

Cuatom class | unordered map | map

Hi Please refer code below : 1. Why temporary object on map causes Constructor Copy contructor two times ? One constructor and one copy contructor (to copy from main to map data) is ok but why third ? Refer objects m1 and um1 in example code. 2. What's the need of reserve on unordered_map ? Isnt hash alone is enough ? What role reserve plays ? Reserve on vector is ok but why for unordered_map ? 3. Why object m2 and um2 calls different number of special functions (unlike m1 and m2 calls same nos.)? https://code.sololearn.com/c3Ac0scIcKmn/?ref=app

19th Mar 2023, 6:27 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 ответов
+ 2
1.try building the map element "in place" with emplace(), like this, to avoid creating first a pair : map<int,test> m1; m1.emplace(1,test()) to answer your second question i will refer you to a well explained post in stack overflow: https://stackoverflow.com/questions/42373232/why-does-stdunordered-map-have-a-reserve-method I don't understand your 3rd question, i'm sorry (i am kinda in a rush today in real life 😅, sorry but maybe someone can explain better )
19th Mar 2023, 11:18 AM
cacgs
+ 1
Thanks
19th Mar 2023, 4:05 PM
Ketan Lalcheta
Ketan Lalcheta - avatar