Chapter 10. Generic Algorithms

1.With only a few exceptions, the algorithms operate over a range of elements. The algorithms that take an input range always use their first two parameters to denote that range.  

2.Ordinarily it is best to usecbegin()and cend()9.2.3, p.334) withalgorithms that read, but do not write, the elements. However, if you plan touse the iterator returned by the algorithm to change an element’s value, thenyou need to passbegin()and end()

3.It is a fairly common beginner mistake to callfill_n(or similar algorithms that write to elements) on a container that has no elements.

4.We frequently use back_inserter to create an iterator to use as the destination ofan algorithm. For example: 

vector<int> vec; // empty vector
// ok: back_inserter creates an insert iterator that adds elements to vec fill_n(back_inserter(vec), 10, 0); // appends ten elements to vec

5.Lambda expression

[capture list] (parameter list) ->return type{ function body

We can omit either or both of the parameter list and return type but must alwaysinclude the capture list and function body:

auto f = [] { return 42; };

Lambdas with function bodies that contain anything other than a singlereturnstatement that do not specify a return type returnvoid

A lambda may use a variable local to its surrounding function only if thelambda captures that variable in its capture list. 

The capture list is used for local nonstaticvariables only; lambdas can uselocalstatics and variables declared outside the function directly. 


6. It is not possible to create a reverse iterator from a forward_list or astream iterator. 

7. We can do so by calling the reverse_iterator’s base member,which gives us its corresponding ordinary iterator 

8.

  • Input iterators : ==!=++*->
  • Output iterators : ++*
  • Forward iterators : ==!=++*->
  • Bidirectional iterators : ==!=++--*->
  • Random-access iterators : ==!=<<=>>=++--++=--=-(two iterators), *->iter[n] == * (iter + n)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值