Skip to content

Commit 545fb8b

Browse files
committed
More typo fixed, up to auto.
1 parent 78c3d64 commit 545fb8b

File tree

12 files changed

+90
-54
lines changed

12 files changed

+90
-54
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <cstdio>
2+
3+
namespace
4+
{
5+
struct system
6+
{
7+
system()
8+
{
9+
printf("sound system\n");
10+
}
11+
};
12+
}
13+
14+
void init_sound_system()
15+
{
16+
system s;
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <cstdio>
2+
3+
struct system
4+
{
5+
system()
6+
{
7+
printf("sound system\n");
8+
}
9+
};
10+
11+
void init_sound_system()
12+
{
13+
system s;
14+
}

examples/static-assert/even_sized_array-11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ struct even_sized_array
88
typedef T type[N];
99
};
1010

11-
// So many less code <3
12-
void foo()
11+
// So much less code <3
12+
void test()
1313
{
1414
even_sized_array<int, 8>::type ok;
1515
even_sized_array<int, 9>::type nok;

examples/static-assert/even_sized_array-98.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct even_sized_array
2020
type;
2121
};
2222

23-
void foo()
23+
void test()
2424
{
2525
even_sized_array<int, 8>::type ok;
2626
even_sized_array<int, 9>::type nok;

examples/uniform-initialization/struct.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct foo_initializer_list
2525
: a(v2), b(v1)
2626
{}
2727

28-
// We will come back to std::initializer list later :)
28+
// An initializer list allows to construct an object using an aggregate-like
29+
// syntax. We will come back to it in @\ref{initializer-list}@ :)
2930
foo_initializer_list(const std::initializer_list<int>& i)
3031
// Note that the fields are set to the same value.
3132
: a(*i.begin()),

parts/11/auto.tex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ \subsection{Auto}
3131
\subsubsection{Auto as a Type Placeholder}
3232

3333
The \code{auto} keyword tells the compiler to deduce the actual type
34-
of a variable from whatever is assigned to it. It can be used every
35-
time a type should be typed, as long as there is an expression the
36-
compiler can use to find the type. It can be augmented with
37-
\code{const} or \code{\&}.
34+
of a variable from whatever is assigned to it. It can be used as long
35+
as there is an expression the compiler can use to find the type. It
36+
can be augmented with \code{const} or \code{\&}.
3837

3938
A typical use is for iterating over an associative container in a for
4039
loop:
@@ -61,7 +60,7 @@ \subsubsection{Auto as a Type Placeholder}
6160

6261
\begin{lstlisting}
6362
template<typename F>
64-
auto foo(F&& f) -> decltype(f())
63+
auto indirect_call(F&& f) -> decltype(f())
6564
{
6665
return f();
6766
}
@@ -78,8 +77,9 @@ \subsubsection{When not to Use \code{auto}}
7877

7978
In practice, the use of this keyword has lead to very painful to read
8079
code, where nothing can be understood without going through every
81-
expression assigned to an \code{auto} variable. This is a very high
82-
load to pass to the next reader.
80+
expression assigned to an \code{auto} variable, and where entire
81+
functions have to be interpreted to eventually find the returned
82+
type. This is a very high load to pass to the next reader.
8383

8484
\begin{guideline}
8585
Mind the next reader; write what you mean.

parts/11/constexpr.tex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ \subsection{\code{constexpr}}
3131

3232
This implementation works but has two major problems: first it is
3333
incredibly verbose, second it forces us to implement the same
34-
algorithm twice, doubling the risk of bugs and errors.
34+
algorithm twice, respectively for run time and compile time
35+
computations, doubling the risk of bugs and errors.
3536

3637
\bigskip
3738

@@ -44,9 +45,4 @@ \subsection{\code{constexpr}}
4445
tell the compiler that it can and should be computed at compile-time
4546
when it appears in constant expressions. It is for example totally
4647
possible to call the \code{constexpr popcount()} function as a
47-
template argument, like in \code{popcount<popcount<42>>()}.
48-
49-
Finally, as an extra bonus, while compilers typically put limits on
50-
the template instantiations depth, i.e. the number of times a template
51-
can be instantiated recursively, there is no such limit to
52-
constexpr functions.
48+
template argument, like in \code{popcount<popcount<42>{}>()}.

parts/11/decltype.tex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
\subsection{Type Deduction with \code{decltype}}
22
\label{decltype}
33

4-
During the pre-\cpp11 every variable, member, argument, etc. has to be
5-
exactly typed. For example, if we were writing a template function
6-
receiving another function as an argument, how could we store the
7-
result of a call of this function in a local variable?
4+
During the pre-\cpp11 era every variable, member, argument, etc. has
5+
to be explicitly typed. For example, if we were writing a template
6+
function operating on a range, how could we declare a variable of the
7+
type of its items?
88

99
\begin{lstlisting}
1010
template
@@ -60,3 +60,6 @@ \subsection{Type Deduction with \code{decltype}}
6060
}
6161
}
6262
\end{lstlisting}
63+
64+
In the example above, \code{decltype(*first)} is the type of the
65+
result of dereferencing \code{first}.

parts/11/lambdas.tex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ \subsection{Lambdas}
6969
{
7070
// Only three lines for the equivalent of the type
7171
// declaration, definition and the instantiation.
72+
// The third argument is a lambda.
7273
return std::find_if
7374
(strings.begin(), strings.end(),
7475
[=](const std::string& string) -> bool
@@ -93,12 +94,12 @@ \subsubsection{The Internals of Lambdas}
9394
[a, b, c]( /* arguments */ ) -> T { /* statements */ }
9495
\end{lstlisting}
9596

96-
is totally equivalent to
97+
is equivalent to
9798

9899
\begin{lstlisting}
99100
struct something
100101
{
101-
T operator( /* arguments */ ) const { /* statements */ }
102+
T operator()( /* arguments */ ) const { /* statements */ }
102103

103104
/* deduced type */ a;
104105
/* deduced type */ b;
@@ -124,9 +125,9 @@ \subsubsection{The Internals of Lambdas}
124125
\item {\it capture} is a list of variables from the parent scope that
125126
must be accessible inside the lambda. Use \code{[=]} to tell the
126127
compiler to automatically copy any variable used by the lambda, or
127-
\code{[\&]} to keep a reference to the used variables from the
128-
parent scope. Variables can also be captured in a fine-grained way,
129-
e.g. \code{[=a, \&b]} to copy the value of \code{a} but store a
128+
\code{[\&]} to keep a reference to the corresponding variables from
129+
the parent scope. Variables can also be captured in a fine-grained
130+
way, e.g. \code{[=a, \&b]} to copy the value of \code{a} but store a
130131
reference to \code{b}.
131132
\item {\it arguments} are the arguments of the function.
132133
\item By default the variables captured by value cannot be assigned to

parts/11/scoped-enumerations.tex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ \subsection{Scoped Enumerations}
22

33
An enumeration in pre-\cpp11 code is just like a C enumeration: a list
44
of constants of type \code{int} in the scope containing the
5-
enumeration. For example, note how \code{foobar::foo} can be accessed
6-
directly and assigned to an integer in the code below:
5+
enumeration. For example, note how \code{appliance::fan} can be
6+
accessed directly and assigned to an integer in the code below:
77

88
\begin{lstlisting}
9-
enum foobar
9+
enum appliance
1010
{
11-
foo,
12-
bar
11+
fan,
12+
oven
1313
};
1414

1515
int main()
1616
{
17-
int v = foo;
17+
int v = fan;
1818
}
1919
\end{lstlisting}
2020

@@ -33,14 +33,14 @@ \subsection{Scoped Enumerations}
3333
enum follower
3434
{
3535
fan,
36-
anonymous
36+
admirer
3737
};
3838
\end{lstlisting}
3939

4040
The above code will fail to compile with a message along the lines of
4141
``error: ‘fan’ conflicts with a previous declaration.'' Now the
4242
typical solution to that was to add a unique prefix to the enumerated
43-
values, but in the times of namespaces and so, is it really a a solution?
43+
values, but in the times of namespaces and so, is it really a solution?
4444

4545
\bigskip
4646

@@ -67,8 +67,8 @@ \subsection{Scoped Enumerations}
6767
enumerations and do not conflict with each other; so if we want to
6868
access a value we must now prefix it with the name of the enumeration,
6969
like in \code{follower::fan}. Moreover, they are also not implicitly
70-
convertible to \code{int} anymore, which may or may not always be good
71-
thing.
70+
convertible to \code{int} anymore, which may or may not always be a
71+
good thing.
7272

7373
The fact that we can also define the type of their values allows for
7474
smaller memory consumption when needed, but also add the possibility

0 commit comments

Comments
 (0)