Skip to content

Tiny fixes after rehearsal of advanced course #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions talk/basicconcepts/classenum.tex
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
VehicleType t = CAR;
\end{cppcode*}
\columnbreak
\begin{cppcode*}{gobble=2}
\begin{cppcode*}{gobble=2,firstnumber=8}
enum VehicleType
: int { // C++11
BIKE = 3,
Expand All @@ -139,7 +139,7 @@
\item strong typing, no automatic conversion to int
\end{itemize}
\small
\begin{cppcode*}{}
\begin{cppcode*}{firstnumber=3}
enum VType { Bus, Car }; enum Color { Red, Blue };
VType t = Bus;
if (t == Red) { /* We do enter */ }
Expand Down Expand Up @@ -210,7 +210,7 @@
\end{cppcode*}
\end{alertblock}
\begin{exampleblock}{\cpp11}
\begin{cppcode*}{gobble=2}
\begin{cppcode*}{gobble=2,firstnumber=4}
using myint = uint64_t;
myint toto = 17;
using pos = int[3];
Expand Down
8 changes: 4 additions & 4 deletions talk/basicconcepts/control.tex
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
\pause
\begin{alertblock}{\cpp98}
Don't confuse with a variable declaration as condition:
\begin{cppcode*}{}
\begin{cppcode*}{firstnumber=7}
if (Value* val = GetValuePtr())
f(*val);
\end{cppcode*}
Expand All @@ -183,7 +183,7 @@
\end{block}
\pause
\begin{exampleblock}{Practical example}
\begin{cppcode*}{}
\begin{cppcode*}{firstnumber=4}
for(int i = 0, j = 0 ; i < 10 ; i++, j = i*i) {
std::cout << i << "^2 is " << j << '\n';
}
Expand Down Expand Up @@ -213,7 +213,7 @@
\end{cppcode*}
\end{block}
\begin{exampleblock}{Example code}
\begin{cppcode*}{}
\begin{cppcode*}{firstnumber=4}
int v[4] = {1,2,3,4};
int sum = 0;
for (int a : v) { sum += a; }
Expand All @@ -236,7 +236,7 @@
\end{cppcode*}
\end{alertblock}
\begin{exampleblock}{\cpp20}
\begin{cppcode*}{}
\begin{cppcode*}{firstnumber=6}
std::array data = {"hello", ",", "world"};
for (std::size_t i = 0; auto& d : data) {
std::cout << i++ << ' ' << d << '\n';
Expand Down
2 changes: 1 addition & 1 deletion talk/basicconcepts/scopesnamespaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
\end{itemize}
\end{block}
\begin{alertblock}{Supersedes static}
\begin{cppcode*}{gobble=2}
\begin{cppcode*}{gobble=2,firstnumber=4}
static int localVar; // equivalent C code
\end{cppcode*}
\end{alertblock}
Expand Down
9 changes: 6 additions & 3 deletions talk/morelanguage/exceptions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@
\end{itemize}
\end{block}
\begin{block}{}
\begin{cppcode*}{gobble=2, linenos=false}
\begin{cppcode*}{gobble=2}
constexpr bool callCannotThrow = noexcept(f());
if constexpr (callCannotThrow) { ... }
\end{cppcode*}
\end{block}
\begin{block}{}
\begin{cppcode*}{gobble=2, linenos=false}
\begin{cppcode*}{gobble=2,firstnumber=3}
template <typename Function>
void g(Function f) noexcept(noexcept(f())) {
...
Expand Down Expand Up @@ -394,7 +394,10 @@
\item Return a \mintinline{cpp}{std::error_code} (\cpp11)
\item If failing to produce a value is not a hard error, consider returning \mintinline{cpp}{std::optional<T>} (\cpp17)
\item Return \mintinline{cpp}{std::expected<T, E>} (\cpp23), where \mintinline{cpp}{T} is the return type on success and \mintinline{cpp}{E} is the type on failure
\item Terminate the program, e.g.\ by calling \mintinline{cpp}{std::terminate()} or \mintinline{cpp}{std::abort()}
\item Terminate the program
\begin{itemize}
\item e.g.\ by calling \mintinline{cpp}{std::terminate()} or \mintinline{cpp}{std::abort()}
\end{itemize}
\item Contracts: Specify function pre- and postconditions. Planned for \cpp20, but removed. Will come back in the future
\end{itemize}
\end{block}
Expand Down
16 changes: 8 additions & 8 deletions talk/objectorientation/typecasting.tex
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
\small
\begin{exampleblock}{}
\begin{cppcode*}{gobble=2}
struct A{ virtual ~A()=default } a;
struct A{ virtual ~A()=default; } a;
struct B : A {} b;

A& c = static_cast<A&>(b); // OK. b is also an A
B& d = static_cast<B&>(a); // UB: a is not a B
B& e = static_cast<B&>(c); // OK. c is a B

B& f = dynamic_cast<B&>(c); // OK, c is a B
B& g = dynamic_cast<B&>(a); // Exception: not a B

B* d = dynamic_cast<B*>(&a); // nullptr. a not a B.
if (d != nullptr) {
// Will not reach this
B& g = dynamic_cast<B&>(a); // throws std::bad_cast
B& foo(A& h) {
return dynamic_cast<B&>(h);
}
B& i = foo(c); // OK, c is a B

if (auto bPtr = dynamic_cast<B*>(&c)) {
// OK, we will get here
B* j = dynamic_cast<B*>(&a); // nullptr. a not a B.
if (j != nullptr) {
// Will not reach this
}
\end{cppcode*}
\end{exampleblock}
Expand Down