Skip to content

Commit 9899c8a

Browse files
committed
Updates from Overleaf
1 parent 740861b commit 9899c8a

10 files changed

+42
-130
lines changed

book.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
%\usepackage{showframe}
55
%\checkandfixthelayout
66

7-
\newcommand{\version}{0.2.1}
7+
\newcommand{\version}{0.3.0}
88
\usepackage{hyperref}
99
\hypersetup{
1010
colorlinks=true,
@@ -33,7 +33,7 @@
3333
\frontmatter
3434
\input{chapters/00_title_page}
3535

36-
\input{chapters/01_preface} % In review
36+
\input{chapters/01_preface} % Reviewed
3737

3838
\mainmatter
3939
\tableofcontents

chapters/01_preface.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ \chapter{Preface}
44

55
\section*{About this book}
66

7-
This book is a complete guide to the \CC standard algorithms. However, that might not mean much to you, so let me unpack this statement.
7+
This book is a complete guide to the \CC\,standard algorithms. However, that might not mean much to you, so let me unpack this statement.
88

99
This book is a guide, as opposed to a reference, meaning that instead of describing every detail, the book concentrates on examples and pointing out notable, surprising, dangerous or interesting aspects of the different algorithms. Furthermore, unlike a reference, it is supposed to be read, for the most part, like a book in sequential order.
1010

11-
\CC already has one canonical reference, the \CC standard, and for quick lookup, the \href{https://cppreference.com}{cppreference.com} wiki is a great source.
11+
\CC\,already has one canonical reference, the \CC\,standard, and for quick lookup, the \href{https://cppreference.com}{cppreference.com} wiki is a great source.
1212

1313
The "complete" part of the statement refers to the width of coverage. The book covers all algorithms and relevant theory up to the \CC20 standard (the \CC23 standard is not finalized at the time of writing). All information is present only in sufficient depth required by the context. This depth limitation keeps the book's overall size reasonable and within the "guide" style.
1414

1515
\section*{About the author}
1616

17-
I am Šimon Tóth, the sole author of this book. My primary qualification is 20 years of \CC experience, with approximately 15 of those years \CC being my primary language in professional settings.
17+
I am Šimon Tóth, the sole author of this book. My primary qualification is 20 years of \CC\,experience, with approximately 15 of those years \CC\,being my primary language in professional settings.
1818

1919
My background is HPC, spanning academia, big tech and startup environments. I have architected, built and operated systems of all scales, from single machine hardware supported high-availability to planet-scale services.\footnote{You can check my \href{https://cz.linkedin.com/in/simontoth}{LinkedIn profile} for a detailed view of my past career.}
2020

chapters/02_introduction.tex

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
\chapter{Introduction}
22

3-
The \CC standard library is arguably quite limited in its functionality. However, when it comes to data and number crunching, the \CC standard library provides a versatile toolkit of algorithms.
3+
The \CC\,standard library is arguably quite limited in its functionality. However, when it comes to data and number crunching, the \CC\,standard library provides a versatile toolkit of algorithms.
44

5-
If you are a \CC developer, good familiarity with \CC standard algorithms can save you a lot of effort and accidental bugs. Notably, whenever you see a raw loop in your code, you should question whether calling a standard algorithm wouldn't be a better solution (it usually is).
5+
If you are a \CC\,developer, good familiarity with \CC\,standard algorithms can save you a lot of effort and accidental bugs. Notably, whenever you see a raw loop in your code, you should question whether calling a standard algorithm wouldn't be a better solution (it usually is).
66

77
\section{History of standard \texorpdfstring{\CC}{C++} algorithms}
88

9-
While each \CC standard introduced new algorithms or variants, there are few notable milestones in the history of \CC standard algorithms.
9+
While each \CC\,standard introduced new algorithms or variants, there are few notable milestones in the history of \CC\,standard 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

@@ -44,7 +44,7 @@ \section{Iterators and ranges}
4444

4545
Algorithms operate on data structures, which poses an issue. How do you abstract the implementation details of a specific data structure and allow the algorithm to work with any data structure that satisfies the algorithm's requirements?
4646

47-
The \CC standard library solution to this problem are iterators and ranges. Iterators encapsulate implementation details of data structure traversal and simultaneously expose a set of operations possible on the given data structure in constant time and space.
47+
The \CC\, standard library solution to this problem are iterators and ranges. Iterators encapsulate implementation details of data structure traversal and simultaneously expose a set of operations possible on the given data structure in constant time and space.
4848

4949
A range is then denoted by a pair of iterators, or more generally, since \CC20, an iterator and a sentinel. In mathematical terms, a pair of iterators \cpp{it1}, \cpp{it2} denotes a range \cpp{[it1, it2)}, that is, the range includes the element referenced by \cpp{it1} and ends before the element referenced by \cpp{it2}.
5050

@@ -121,4 +121,16 @@ \subsection{Restrictions on invocable}
121121

122122
These restrictions in practice mean that the passed invocable must be regular. The invocable must return the same result if invoked again with the same arguments. This definition permits accessing a global state such as a cache but does not permit invocables that change their result based on their internal state (such as generators).
123123

124-
\section{A simple mental model for iterators}
124+
\section{A simpler mental model for iterators}
125+
126+
It can be tricky to internalize all the rules associated with iterators when working with standard algorithms. One shorthand that can help is to think in terms of ranges instead of iterators.
127+
128+
Ranges passed in as arguments are usually apparent, typically specified by pair of iterators.
129+
130+
131+
132+
The less obvious can be the ranges returned by the algorithms. In some cases, the range is evident from the algorithm.
133+
134+
In some cases, a single returned iterator denotes multiple ranges.
135+
136+
Even when the algorithms seem to return an iterator to a specific element, we can still think of the output as a range.

chapters/03_algorithms_14_uninitialized.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ \subsection{\texorpdfstring{\cpp{std::construct_at}, \cpp{std::destroy_at}}{\tex
2121
\cppfile{code_examples/algorithms/create_at_code.h}
2222
\end{box-note}
2323

24-
\subsection{\texorpdfstring{\cpp{std::uninitialized_default_construct},\newline\cpp{std::uninitialized_value_construct},\newline\cpp{std::uninitialized_fill}, \newline\cpp{std::destroy}}{\texttt{std::uninitialized\_default\_construct},\newline\texttt{std::uninitialized_value_construct},\newline\texttt{std::uninitialized_fill}, \newline\texttt{std::destroy}}}
24+
\subsection{\texorpdfstring{\cpp{std::uninitialized_default_construct},\newline\cpp{std::uninitialized_value_construct},\newline\cpp{std::uninitialized_fill}, \newline\cpp{std::destroy}}{\texttt{std::uninitialized\_default\_construct},\newline\texttt{std::uninitialized\_value\_construct},\newline\texttt{std::uninitialized\_fill}, \newline\texttt{std::destroy}}}
2525
\index{\cpp{std::uninitialized_default_construct}}
2626
\index{\cpp{std::uninitialized_value_construct}}
2727
\index{\cpp{std::uninitialized_fill}}

chapters/03_algorithms_17_minmax.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ \subsection{\texorpdfstring{\cpp{std::clamp}}{\texttt{std::clamp}}}
7777
\cppfile{code_examples/algorithms/clamp_code.h}
7878
\end{box-note}
7979

80-
\subsection{\texorpdfstring{\cpp{std::min_element}, \cpp{std::max_element}, \cpp{std::minmax_element}}{\texttt{std::min\_element}, \texttt{std::max\_element}, \texttt{std::minmax\_element}}}
80+
\subsection{\texorpdfstring{\cpp{std::min_element}, \cpp{std::max_element}, \newline\cpp{std::minmax_element}}{\texttt{std::min\_element}, \texttt{std::max\_element},
81+
\textCR\texttt{std::minmax\_element}}}
8182
\index{\cpp{std::min_element}}
8283
\index{\cpp{std::max_element}}
8384
\index{\cpp{std::minmax_element}}

chapters/04_ranges_in_depth.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ \subsection{\texorpdfstring{\cpp{std::views::all}}{\texttt{std::views::all}}}
225225
\cppfile{code_examples/views/all_code.h}
226226
\end{box-note}
227227

228-
\subsection{\texorpdfstring{\cpp{std::views::split}, \cpp{std::views::lazy_split}, \cpp{std::views::join_view}}{\texttt{std::views::split}, \texttt{std::views::lazy\_split}, \texttt{std::views::join\_view}}}
228+
\subsection{\texorpdfstring{\cpp{std::views::split}, \cpp{std::views::lazy_split}, \newline\cpp{std::views::join_view}}{\texttt{std::views::split}, \texttt{std::views::lazy\_split}, \textCR\texttt{std::views::join\_view}}}
229229
\index{\cpp{std::views::split}}
230230
\index{\cpp{std::views::lazy_split}}
231231
\index{\cpp{std::views::join_view}}

packages/code_blocks.tex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
% Overleaf botch. Normally we use minted files in the build folder, but Overleaf needs special care.
12
\def\StripPrefix#1>{}
23
\def\isOverleaf{\fi
34
\def\overleafJobname{output}% overleaf defaults to 'output' as \jobname
@@ -19,6 +20,9 @@
1920

2021
\newminted{cpp}{
2122
linenos=true,
23+
firstnumber=1,
24+
tabsize=4,
25+
obeytabs,
2226
xleftmargin=1em,
2327
breaklines,
2428
fontsize=\footnotesize,
@@ -34,4 +38,6 @@
3438
breaklines,
3539
fontsize=\footnotesize,
3640
numbersep=0.75em
37-
}
41+
}
42+
43+
\newmintinline[cpp]{cpp}{}

packages/color_blocks.tex

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,15 @@
11
\usepackage[many]{tcolorbox} % for COLORED BOXES (tikz and xcolor included)
2-
\usepackage{xcolor}
3-
4-
\tcbset{
5-
sharp corners,
6-
colback = white,
7-
before skip = 0.2cm, % add extra space before the box
8-
after skip = 0.5cm % add extra space after the box
9-
} % setting global options for tcolorbox
10-
11-
\newtcolorbox{box-info}{
12-
colback = LightSkyBlue!20,
13-
colframe = MidnightBlue!50,
14-
boxrule = 0pt,
15-
leftrule = 6pt, % left rule weight
16-
fontupper=\sffamily
17-
}
18-
19-
\newtcolorbox{box-warning}{
20-
colback = LightGoldenrodYellow,
21-
colframe = LightGoldenrod,
22-
boxrule = 0pt,
23-
leftrule = 6pt, % left rule weight
24-
fontupper=\sffamily
25-
}
26-
27-
\newtcolorbox{box-critical}{
28-
colback = LightSalmon!20,
29-
colframe = OrangeRed!80,
30-
boxrule = 0pt,
31-
leftrule = 6pt, % left rule weight
32-
fontupper=\sffamily
33-
}
342

353
\newtcolorbox{box-note}{
364
sharpish corners, % better drop shadow
375
boxrule = 0pt,
386
toprule = 4.5pt, % top rule weight
397
enhanced,
408
breakable,
9+
enlarge top by=5pt,
10+
colback = white,
11+
before skip = 0.2cm, % add extra space before the box
12+
after skip = 0.5cm, % add extra space after the box
4113
drop fuzzy shadow = black!35,
4214
fontupper=\sffamily
4315
}

packages/local.tex

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
\usepackage{sidenotes}
2-
\usepackage{multirow}
1+
\usepackage{sidenotes} % Required
2+
\usepackage{multirow} % Required
3+
\usepackage{diagbox} % Used for boolean algorithms.
34

45
% Command to consistently format side-panel with C++ versions that introduced different variants of the algorithm.
56
\newcommand{\cppversions}[5]{
@@ -19,6 +20,7 @@
1920
\end{margintable}
2021
}
2122

23+
% Command to consistently format the algorithm info table.
2224
\newcommand{\constraints}[4]{
2325
\begin{center}
2426
\footnotesize
@@ -45,8 +47,4 @@
4547
\hline
4648
\end{tabular}
4749
\end{center}
48-
}
49-
50-
\newmintinline[cpp]{cpp}{}
51-
52-
\usepackage{diagbox}
50+
}

packages/slashbox.sty

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)