|
4 | 4 | \frametitlecpp[20]{Ranges}
|
5 | 5 | \begin{block}{The range concept}
|
6 | 6 | \begin{itemize}
|
7 |
| - \item A range is a group of items that you can iterate over |
| 7 | + \item A range is a sequence of items that you can iterate over |
8 | 8 | \item It must provide iterators to its beginning and end, obtainable via \mintinline{cpp}{std::range::begin} and \mintinline{cpp}{std::range::end}
|
9 | 9 | \item Range concepts are located in \mintinline{cpp}{std::ranges} namespace
|
10 | 10 | \item All STL containers are ranges
|
11 | 11 | \end{itemize}
|
12 | 12 | \end{block}
|
13 | 13 | \begin{exampleblock}{Variations on ranges}
|
14 |
| - There are actually different type of ranges |
| 14 | + There are actually different types of ranges |
15 | 15 | \begin{itemize}
|
16 | 16 | \item \mintinline{cpp}{input_range}, \mintinline{cpp}{output_range}, \mintinline{cpp}{forward_range}, \mintinline{cpp}{bidirectional_range}, \mintinline{cpp}{random_access_range}, \mintinline{cpp}{contiguous_range}
|
17 | 17 | \item corresponding to the different iterator categories
|
|
25 | 25 | \begin{itemize}
|
26 | 26 | \item A \mintinline{cpp}{view} is a non-owning object built from a range or another view after applying some range adaptor(s)
|
27 | 27 | \item The time complexity to copy, move, assign is constant
|
28 |
| - \item Range adaptors can be applied/changed with \mintinline{cpp}{|} and are lazy |
| 28 | + \item Range adaptors can be applied/chained with \mintinline{cpp}{|} and are lazy |
29 | 29 | \item They live in the \mintinline{cpp}{std::views} namespace
|
30 | 30 | \item They introduce easy functional programming to the STL
|
31 | 31 | \end{itemize}
|
32 | 32 | \end{block}
|
33 | 33 | \begin{exampleblock}{Example}
|
34 |
| - { \scriptsize |
| 34 | + { \small |
35 | 35 | \begin{cppcode*}{gobble=4}
|
36 | 36 | auto const numbers = std::views::iota(0, 6);
|
37 | 37 | auto even = [](int i) { return 0 == i % 2; };
|
|
64 | 64 |
|
65 | 65 | \begin{frame}[fragile]
|
66 | 66 | \frametitlecpp[23]{Back to laziness}
|
67 |
| - \begin{exampleblock}{\texttt{view}s are lazy} |
| 67 | + \begin{block}{Views are lazy} |
68 | 68 | \begin{itemize}
|
69 | 69 | \item Computation is only triggered when iterating
|
70 | 70 | \item And can be stopped by e.g. \mintinline{cpp}{take}
|
71 | 71 | \item Here, the minimal number of iterations is performed
|
72 | 72 | \end{itemize}
|
73 |
| - { \scriptsize |
74 |
| - \begin{cppcode*}{gobble=2} |
75 |
| - // print first 20 prime numbers above 1000000 |
76 |
| - for (int i: std::views::iota(1000000) | std::views::filter(odd) |
77 |
| - | std::views::filter(isPrime) |
78 |
| - | std::views::take(20)) { |
79 |
| - std::cout << i << " "; |
80 |
| - } |
81 |
| - \end{cppcode*} |
82 |
| - } |
| 73 | + \end{block} |
| 74 | + \begin{exampleblock}{Example} |
| 75 | + \begin{cppcode*}{gobble=2} |
| 76 | + // print first 20 prime numbers above 1000000 |
| 77 | + for (int i: std::views::iota(1000000) |
| 78 | + | std::views::filter(odd) |
| 79 | + | std::views::filter(isPrime) |
| 80 | + | std::views::take(20)) { |
| 81 | + std::cout << i << " "; |
| 82 | + } |
| 83 | + \end{cppcode*} |
83 | 84 | \end{exampleblock}
|
84 | 85 | \end{frame}
|
0 commit comments