Chaper 11. Associate Container

1.

The associative containers do not support the sequential-container position-specific operations, suchas push_front or back

The associative containers do not support the constructors or insert operations that take anelement value and a count. 

The associative container iterators are bidirectional.

2.

When we initialize a map, we have to supply both the key and the value. We wrap each key–value pair inside curly braces:

{key, value

3.

When we dereference an iterator, we get a reference to a value of the container’svalue_type. In the case of map, the value_type is a pair in which first holdsthe const key and second holds the value 

4.

Although the set types define both the iterator and const_iterator types, both types of iterators give us read-only access to the elements in the set. Just as we cannot change the key part of a map element, the keys in a set are also const. Wecan use a set iterator to read, but not write, an element’s value.

5.

When we use an iteratorto traverse a map, multimap, set, or multiset, the iterators yieldelements in ascending key order. 


6.

For the containers that have unique keys, the versions of insert and emplace that add a single element return a pair that lets us know whether the insertion happened. The first member of the pair is an iterator to the element with the given key; the second is a bool indicating whether that element was inserted, or was already there. If the key is already in the container, then insert does nothing, and the bool portion of the return value is false. If the key isn’t present, then the element is inserted and the bool is true

For the containers that allow multiple keys, the insert operation that takes a singleelement returns an iterator to the new element. 


7.

Today I was trying to use:
auto ret = iset.insert(std::advance(itr, 3), 1);
Compiler complained an error. The reason is that the function returns void. itr is a reference parameter. That's how its value gets changed.

8.

we can erase one element or a rangeof elements by passing erase an iterator or an iterator pair.


9.

Because the subscript operator might insert an element, we may use subscript only ona map that is not const

10.P547

c.find(k), c.count(k), c.lower_bound(k), c.upper_bound(k), c.equal_range(k)

11.

We are guaranteed that iterating across a multimap or multiset returnsall the elements with a given key in sequence. 


12.

If the key is in the container, the iterator returned from lower_bound will refer to the first instance ofthat key and the iterator returned by upper_bound will refer just after the last instance of the key. 

If the element is not in the multimap, then lower_bound andupper_bound will return equal iterators; both will refer to the point at which the key can be inserted without disrupting the order. 

This function equal_range takes a key and returns a pair of iterators. If the key is present, then the first iterator refers to the first instance of the key and the second iterator refers one past the last instance of the key. If no matching element is found, then both the first and second iterators refer to the position where this key can be inserted. 

13.

Use an unordered container if the key type is inherently unordered or ifperformance testing reveals problems that hashing might solve.

page556image9264



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值