effective stl 笔记

Item 22
-change an element in a set or multiset, you must be sure not to change a key part.【76~78】
-some implementations keeps the elements of set/multiset from being modified by having operator* for a set<T>::iterator return a const T&.【78】
-use "cast to a reference" to change a non-key portion of an element in a set or a multiset.【79】
-"cast to a object" don't work because the result of the cast is a temporary anonymous object【79】
-★by casting to a reference,we avoid creating a new object. Instead, the result of the cast is a reference to anexisting object【80】
-the first component of the pair whitch is the element of the map is defined to be const【80】
-how to change an element in a set, multiset, map, or multimap without cast【80】

Item 30
-the iterator return by back_inserter causes push_back to be called【p107】
-front_inserter causes "reverse", iterate over values in reverse order(values.rbegin(). values.rend(),) to keep the output to be in the same order as corresponding objects.【p108】
-inserters make each insertion into the destination range is done one object at a time.it's expansive for contiguous-memory containers.vector or string can minimize the expense by "reserve()".【p108】
-clear the destination range and use an inserter to overwrite.【p110】

Item 31
-partial_sort:partially put things in order【p111】
-nth_element:identify the top n elements or the element at a particular position【p111】
-partial_sort and nth_element are not stable sorts【p112】
-stable_sort【p112】
-patition/stable_partition:identify all the elements with a quality rating range【p114】
-sort, stable_sort, partial_sort, and nth_element require random access iterators.【p114】
-list offers its sort member funcion(a stable sort).【p114】
-partition and stable_partition require only bidirectional iterators.【p115】
-summarize【p115】

Item 32
-list's member function remove merges remove and erase.【119】
-don't eleminate elements! remove_if and unique are the same【119】
-list::unique really remove things【119】

Item 33
-replace the container of pointers with a container of smart pointers,us the erase-remove idiom directly.【122】
-shared_ptr template in the Boost library.【123】

Item 34
-not all algorithms are applicable to all ranges:
  remove requires forward iterators and the ability to make assignments.it can't be applied to input iterators, nor to maps or multimaps, nor to some implementations of set and multiset【p123】
  many of the sorting algorithms demand random access iterators, so it's not possible to invoke these algorithms on the elements of a list.【p123】
-

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值