Reputation: 131
typedef tr1::unordered_map <string, pin *> pin_cmp;
pin_cmp _pin_cmp;
_Pins[_num_pins] = new pin (pin_id, _num_pins, s, n, d);
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
Could you teach me what actually the code doing?
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
I am not familiar with unordered_map which still can use with array[].I am confuse unordered_map just need key and value why will have array[]?
Upvotes: 0
Views: 442
Reputation: 1717
In above example I expect _Pins
to be a sequential container.
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
This line of code accesses a element _Pins[_num_pins]
twice:
Then the object is placed inside _pin_cmp
(unordered map) using the name of the object as index.
Exact behavior of this operation is described here.
Upvotes: 1