0
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[]?

4

1 回答 1

1

在上面的示例中,我希望_Pins成为一个顺序容器。

_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling

这行代码访问一个元素_Pins[_num_pins]两次:

  1. 在右侧获取对象
  2. 在左侧获取对象的名称。

_pin_cmp然后使用对象的名称作为索引将对象放置在内部(无序映射)。此处描述了此操作的确切行为。

于 2013-06-17T05:57:41.050 回答