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)
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.
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)