Skip to content

Commit 66863c6

Browse files
committed
Updates from Overleaf
1 parent f2e3a91 commit 66863c6

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

book.tex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838
\mainmatter
3939
\tableofcontents
4040

41-
\input{chapters/02_introduction} % In review
41+
%\input{chapters/02_introduction} % In review
4242
%\input{chapters/03_algorithms_00_main} % In review
4343
%\input{chapters/04_ranges_in_depth} % In review
4444

45+
\input{chapters/90_theory} % TODO
46+
4547
\appendix
4648
\input{chapters/XX_index}
4749

50+
% Section on iterator invalidation
51+
4852
\backmatter
4953

5054
\end{document}

chapters/02_introduction.tex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ \section{History of standard \texorpdfstring{\CC}{C++} algorithms}
1010

1111
The \CC98 standard introduced most of the algorithms. However, it was the \CC11 standard with its introduction of lambdas that made algorithms worthwhile. Before lambdas, the time investment of writing a custom function object made the usefulness of algorithms dubious.
1212

13-
\begin{box-note}
13+
\raggedbottom
14+
\begin{box-nobreak}
1415
\footnotesize Example of \cpp{std::for_each}\index{\cpp{std::for_each}} algorithm with a custom function object, calculating the number of elements and their sum.
1516
\tcblower
1617
\cppfile{code_examples/introduction/history_cc98_code.h}
17-
\end{box-note}
18+
\end{box-nobreak}
1819

1920
\begin{box-note}
2021
\footnotesize Example of \cpp{std::for_each}\index{\cpp{std::for_each}} algorithm with a capturing lambda, calculating the number of elements and their sum.
@@ -153,3 +154,8 @@ \section{A simpler mental model for iterators}
153154

154155
Even when the algorithm returns an iterator to a specific element, it might be worth considering the implied range.
155156

157+
\begin{box-note}
158+
\footnotesize Example of \cpp{std::find} establishing a prefix range that doesn't contain the searched-for element.
159+
\tcblower
160+
\cppfile{code_examples/introduction/mental_find_code.h}
161+
\end{box-note}

chapters/03_algorithms_01_foreach.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ \section{Introducing the algorithms}
77
\begin{enumerate}[label=\protect\circled{\arabic*}]
88
\item The presentation of each algorithm will start with a short description.
99
\item The margin will contain information about the history of the algorithm: which C++ standard introduced it and whether it has constexpr, parallel and range variants and including versions of the standard that introduced them.
10-
\item Following that will be the description of constraints. Algorithms that write data to a distinct output range are denoted with an arrow: \cpp{input_range -> output_range}.
10+
\item Following that will be the description of constraints. Algorithms that write data to a distinct output range are denoted with an arrow: \newline\cpp{input_range -> output_range}.
1111
\item Finally, each description will conclude with one or more examples with explanations.
1212
\end{enumerate}
1313

@@ -36,7 +36,7 @@ \subsection{\texorpdfstring{\cpp{std::for_each}}{\texttt{std::for\_each}}}
3636
\end{tabular}
3737
\end{center}
3838

39-
\circled{4} The C++11 standard introduced the range loop, which mostly replaced the uses of \cpp{std::for_each}.
39+
\circled{4} The C++11 standard introduced the range-based for loop, which mostly replaced the uses of \cpp{std::for_each}.
4040

4141
\begin{box-note}
4242
\footnotesize Example of a range loop over all elements of a \cpp{std::vector}.
@@ -52,7 +52,7 @@ \subsection{\texorpdfstring{\cpp{std::for_each}}{\texttt{std::for\_each}}}
5252

5353
However, there are still a few corner cases when using \cpp{std::for_each} is preferable.
5454

55-
The first case is straightforward parallelization. Invoking an expensive operation for each element in parallel is trivial with \cpp{std::for_each}. On top of that, as long as the operations are independent, there is no need for synchronization primitives.
55+
The first case is straightforward parallelization. Invoking an expensive operation for each element in parallel is trivial with \cpp{std::for_each}. As long as the operations are independent, there is no need for synchronization primitives.
5656

5757
\begin{box-note}
5858
\footnotesize Example of a parallel \cpp{std::for_each} invoking a method on each element independently in parallel.
@@ -63,7 +63,7 @@ \subsection{\texorpdfstring{\cpp{std::for_each}}{\texttt{std::for\_each}}}
6363
Second, the range version can provide a more concise and explicit syntax in some cases because of the projection support introduced in C++20.
6464

6565
\begin{box-note}
66-
\footnotesize Example of the range version \cpp{std::ranges::for_each} utilizing a projection to iterate over the result of invoking the method \cpp{getValue()} on each element.
66+
\footnotesize Example of the range version of \cpp{std::ranges::for_each} utilizing a projection to invoke the method \cpp{getValue()} (line 13) on each element and summing the resulting values using a lambda (line 12).
6767
\tcblower
6868
\cppfile{code_examples/algorithms/for_each_code_cpp20.h}
6969
\end{box-note}

chapters/90_theory.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\chapter{In-depth}
2+
3+
In this chapter, we will go over relevant in-depth topics referenced throughout the rest of the book.
4+
5+
\section{Argument-dependent lookup (ADL)}
6+
7+
When calling a method without qualification (i.e. not specifying the namespace), the compiler needs to determine the set of candidate functions. As a first step, the compiler will do an unqualified name lookup, which starts at the local scope and examines the parent scopes until it finds the first instance of the name (at which point it stops).
8+
9+
\begin{box-note}
10+
\footnotesize Example of unqualified lookup. Both calls to \cpp{some_call} will resolve to \cpp{::A::B::some_call} since this is the first instance discovered by the compiler.
11+
\tcblower
12+
\cppfile{code_examples/theory/adl_unqualified.h}
13+
\end{box-note}

packages/color_blocks.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@
1212
after skip = 0.5cm, % add extra space after the box
1313
drop fuzzy shadow = black!35,
1414
fontupper=\sffamily
15+
}
16+
17+
\newtcolorbox{box-nobreak}{
18+
sharpish corners, % better drop shadow
19+
boxrule = 0pt,
20+
toprule = 4.5pt, % top rule weight
21+
enhanced,
22+
enlarge top by=5pt,
23+
colback = white,
24+
before skip = 0.2cm, % add extra space before the box
25+
after skip = 0.5cm, % add extra space after the box
26+
drop fuzzy shadow = black!35,
27+
fontupper=\sffamily
1528
}

0 commit comments

Comments
 (0)