Skip to content

Commit c042df4

Browse files
Sebastien Poncesponce
authored andcommitted
Introduced exampleblockGB environment for examples with godbolt links
And added also an index of godbolt code examples at the end
1 parent dc4a396 commit c042df4

File tree

13 files changed

+86
-52
lines changed

13 files changed

+86
-52
lines changed

talk/C++Course.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,9 @@ \section*{Index}
217217
\listofexercises
218218
\end{frame}
219219

220+
\begin{frame}
221+
\frametitle{Index of Godbolt code examples}
222+
\listofgodbolt
223+
\end{frame}
224+
220225
\end{document}

talk/basicconcepts/assert.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
\item The program will be aborted if the assertion fails
1313
\end{itemize}
1414
\end{block}
15-
\begin{exampleblock}{assert in practice - \godboltLink{https://godbolt.org/z/eo78cY7hM}}
15+
\begin{exampleblockGB}{\texttt{assert} in practice}{https://godbolt.org/z/eo78cY7hM}{\texttt{assert}}
1616
\begin{overprint}
1717
\onslide<1>
1818
\begin{cppcode*}{}
@@ -32,7 +32,7 @@
3232
Abort trap: 6
3333
\end{Verbatim}
3434
\end{overprint}
35-
\end{exampleblock}
35+
\end{exampleblockGB}
3636
\end{frame}
3737

3838
\begin{frame}[fragile]

talk/concurrency/mutexes.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
\begin{frame}[fragile]
44
\frametitlecpp[11]{Races}
5-
\begin{exampleblock}{Example code \godboltLink{https://godbolt.org/z/oGz61Pn19}}
5+
\begin{exampleblockGB}{Example code}{https://godbolt.org/z/oGz61Pn19}{Race}
66
\begin{cppcode*}{}
77
int a = 0;
88
void inc() { a++; };
@@ -16,7 +16,7 @@
1616
std::cout << a << "\n";
1717
}
1818
\end{cppcode*}
19-
\end{exampleblock}
19+
\end{exampleblockGB}
2020
\pause
2121
\begin{block}{What do you expect? (Exercise code/race)}
2222
\pause
@@ -98,7 +98,7 @@
9898
\end{description}
9999
\end{block}
100100
\pause
101-
\begin{exampleblock}{Practically \godboltLink{https://godbolt.org/z/a5TaaPrad}}
101+
\begin{exampleblockGB}{Practically}{https://godbolt.org/z/a5TaaPrad}{\texttt{mutex}}
102102
\begin{cppcode*}{}
103103
int a = 0;
104104
std::mutex m;
@@ -107,7 +107,7 @@
107107
a++;
108108
}
109109
\end{cppcode*}
110-
\end{exampleblock}
110+
\end{exampleblockGB}
111111
\end{frame}
112112

113113
\begin{frame}[fragile]

talk/expert/coroutines.tex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ \subsection{Coroutines}
234234
\begin{frame}[fragile]
235235
\frametitlecpp[20]{Resuming a coroutine}
236236
\scriptsize
237-
\begin{block}{User code - \godboltLink{https://godbolt.org/z/qx46Pa4v3}}
237+
\begin{exampleblockGB}{User code}{https://godbolt.org/z/qx46Pa4v3}{Resuming a coroutine}
238238
\begin{cppcode*}{gobble=2}
239239
Task myCoroutine() {
240240
std::cout << "Step 1 of coroutine\n";
@@ -252,7 +252,7 @@ \subsection{Coroutines}
252252
// c.resume(); // would segfault!
253253
}
254254
\end{cppcode*}
255-
\end{block}
255+
\end{exampleblockGB}
256256
\begin{block}{}
257257
\begin{minted}[gobble=4]{text}
258258
Step 1 of coroutine
@@ -350,7 +350,7 @@ \subsection{Coroutines}
350350

351351
\begin{frame}[fragile]
352352
\frametitlecpp[20]{\texttt{co\_yield} - final usage}
353-
\begin{exampleblock}{Finally, we can use the generator nicely - \godboltLink{https://godbolt.org/z/6bbrYrss5}}
353+
\begin{exampleblockGB}{Finally, we can use the generator nicely}{https://godbolt.org/z/6bbrYrss5}{\texttt{co\_yield}}
354354
{\scriptsize
355355
\begin{cppcode*}{gobble=4}
356356
Task range(int first, int last) {
@@ -363,7 +363,7 @@ \subsection{Coroutines}
363363
} // 1 2 3 4 5 6 7 8 9
364364
\end{cppcode*}
365365
}
366-
\end{exampleblock}
366+
\end{exampleblockGB}
367367
\pause
368368
\begin{alertblock}{Wait a minute: 0 is missing in the output!}
369369
\begin{itemize}
@@ -386,7 +386,7 @@ \subsection{Coroutines}
386386

387387
\begin{frame}[fragile]
388388
\frametitlecpp[20]{Laziness allows for infinite ranges}
389-
\begin{block}{Generators do not need to be finite - \godboltLink{https://godbolt.org/z/MP6qdGWYe}}
389+
\begin{exampleblockGB}{Generators do not need to be finite}{https://godbolt.org/z/MP6qdGWYe}{Infinite generator}
390390
\begin{cppcode*}{gobble=2}
391391
Task range(int first) {
392392
while (true) {
@@ -397,12 +397,12 @@ \subsection{Coroutines}
397397
std::cout << i << "\n";
398398
}
399399
\end{cppcode*}
400-
\end{block}
400+
\end{exampleblockGB}
401401
\end{frame}
402402

403403
\begin{frame}[fragile]
404404
\frametitlecpp[20]{Real life example}
405-
\begin{block}{A Fibonacci generator, from \cpprefLink{https://en.cppreference.com/w/cpp/language/coroutines} - \godboltLink{https://godbolt.org/z/3Pev1M8se}}
405+
\begin{exampleblockGB}{A Fibonacci generator, from \cpprefLink{https://en.cppreference.com/w/cpp/language/coroutines}}{https://godbolt.org/z/3Pev1M8se}{Fibonacci generator}
406406
\scriptsize
407407
\begin{cppcode*}{gobble=2}
408408
Task<long long int> fibonacci(unsigned n) {
@@ -427,7 +427,7 @@ \subsection{Coroutines}
427427
}
428428
}
429429
\end{cppcode*}
430-
\end{block}
430+
\end{exampleblockGB}
431431
\end{frame}
432432

433433
\begin{frame}
@@ -495,7 +495,7 @@ \subsection{Coroutines}
495495

496496
\begin{frame}[fragile]
497497
\frametitlecpp[20]{\texttt{awaiter} example}
498-
\begin{block}{Switch to new thread, from \cpprefLink{https://en.cppreference.com/w/cpp/language/coroutines} - \godboltLink{https://godbolt.org/z/K7svE4P7s}}
498+
\begin{exampleblockGB}{Switch to new thread, from \cpprefLink{https://en.cppreference.com/w/cpp/language/coroutines}}{https://godbolt.org/z/K7svE4P7s}{Thread switching}
499499
\scriptsize
500500
\begin{cppcode*}{gobble=2}
501501
auto switch_to_new_thread(std::jthread& out) {
@@ -520,7 +520,7 @@ \subsection{Coroutines}
520520
resuming_on_new_thread(out);
521521
}
522522
\end{cppcode*}
523-
\end{block}
523+
\end{exampleblockGB}
524524
\pause
525525
\vspace{-2.1cm}
526526
\begin{columns}
@@ -529,14 +529,14 @@ \subsection{Coroutines}
529529
\begin{column}{.55\textwidth}
530530
\setlength{\textwidth}{5.4cm}
531531
\raggedright
532-
\begin{exampleblock}{Output}
532+
\begin{block}{Output}
533533
\scriptsize
534534
\begin{minted}[gobble=9]{text}
535535
Started on thread: 140144191063872
536536
New thread ID: 140144191059712
537537
Resumed on thread: 140144191059712
538538
\end{minted}
539-
\end{exampleblock}
539+
\end{block}
540540
\end{column}
541541
\end{columns}
542542
\end{frame}

talk/expert/cpp20concepts.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
leading to a substitution failure
2121
\end{itemize}
2222
\end{block}
23-
\begin{exampleblock}{Practical code \godboltLink{https://godbolt.org/z/e4T9q1jfh}}
23+
\begin{exampleblockGB}{Practical code}{https://godbolt.org/z/e4T9q1jfh}{SFINAE failure}
2424
\scriptsize
2525
\begin{cppcode*}{}
2626
template
@@ -46,7 +46,7 @@
4646
.../type_traits:2514:11: |fvtextcolor[red][error:] no type named 'type' in 'struct std::enable_if<false, void>'
4747
2514 | using |fvtextcolor[red][enable_if_t] = typename enable_if<_Cond, _Tp>::type;
4848
\end{Verbatim}
49-
\end{exampleblock}
49+
\end{exampleblockGB}
5050
\end{frame}
5151

5252
\begin{frame}[fragile]
@@ -56,7 +56,7 @@
5656
\item The keyword \mintinline{cpp}{requires} lets us define various constraints.
5757
\end{itemize}
5858
\end{block}
59-
\begin{exampleblock}{With concepts \godboltLink{https://godbolt.org/z/dWvM9Pvee}}
59+
\begin{exampleblockGB}{With concepts}{https://godbolt.org/z/dWvM9Pvee}{concept failure}
6060
\scriptsize
6161
\begin{cppcode*}{}
6262
template<typename T>
@@ -81,7 +81,7 @@
8181
|fvtextcolor[blue][<source>:6:15:] |fvtextcolor[blue!50!green][note:] |fvtextcolor[blue][the expression 'is_floating_point_v<T> [with T = int]' evaluated to 'false']
8282
6 | requires |fvtextcolor[blue!50!green][std::is_floating_point_v<T>]
8383
\end{Verbatim}
84-
\end{exampleblock}
84+
\end{exampleblockGB}
8585
\end{frame}
8686

8787
\begin{frame}[fragile]

talk/expert/cpp20spaceship.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
\begin{frame}[fragile]
4848
\frametitlecpp[20]{The three-way comparison operator practically}
49-
\begin{exampleblock}{Output of \texttt{operator<=>} - \godboltLink{https://godbolt.org/z/o6Er1zjrf}}
49+
\begin{exampleblockGB}{Output of \texttt{operator<=>}}{https://godbolt.org/z/o6Er1zjrf}{\texttt{<=>} output}
5050
\begin{cppcode*}{}
5151
template <typename T>
5252
void three_way_compare( T lhs, T rhs ) {
@@ -61,7 +61,7 @@
6161
three_way_compare(2, 1); // 2<=>1: 001
6262
}
6363
\end{cppcode*}
64-
\end{exampleblock}
64+
\end{exampleblockGB}
6565
\end{frame}
6666
6767
\begin{frame}[fragile]
@@ -92,7 +92,7 @@
9292
\begin{frame}[fragile]
9393
\frametitlecpp[20]{Exercising different orderings}
9494
\scriptsize
95-
\begin{exampleblock}{Example \godboltLink{https://godbolt.org/z/s8Gdae4bW}}
95+
\begin{exampleblockGB}{Example}{https://godbolt.org/z/s8Gdae4bW}{various orderings}
9696
\begin{cppcode*}{}
9797
struct Ratio {
9898
unsigned n, d ;
@@ -116,7 +116,7 @@
116116
three_way_compare(0., 0./0.); // 0<=>-nan : 000
117117
}
118118
\end{cppcode*}
119-
\end{exampleblock}
119+
\end{exampleblockGB}
120120
\end{frame}
121121
122122
\begin{frame}[fragile]

talk/expert/sfinae.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128

129129
\begin{frame}[fragile]
130130
\frametitlecpp[11]{Not so easy actually...}
131-
\begin{exampleblock}{Example \godboltLink{https://godbolt.org/z/Y9Ys4hvWq}}
131+
\begin{exampleblockGB}{Example}{https://godbolt.org/z/Y9Ys4hvWq}{\texttt{hasFoo} failing}
132132
\small
133133
\begin{cppcode*}{}
134134
template <typename T, typename = void>
@@ -146,7 +146,7 @@
146146
static_assert(!hasFoo<C>::value, "C has no foo()");
147147
static_assert(hasFoo<C,int>::value, "C has foo()");
148148
\end{cppcode*}
149-
\end{exampleblock}
149+
\end{exampleblockGB}
150150
\end{frame}
151151

152152
\begin{frame}[fragile]
@@ -168,7 +168,7 @@
168168

169169
\begin{frame}[fragile]
170170
\frametitlecpp[17]{Previous introspection example using \texttt{void\_t}}
171-
\begin{exampleblock}{Example \godboltLink{https://godbolt.org/z/hfMxndP1x}}
171+
\begin{exampleblockGB}{Example}{https://godbolt.org/z/hfMxndP1x}{\texttt{hasFoo} working}
172172
\begin{cppcode*}{}
173173
template <typename T, typename = void>
174174
struct hasFoo : std::false_type {};
@@ -185,7 +185,7 @@
185185
static_assert(hasFoo<B>::value, "expected foo()");
186186
static_assert(hasFoo<C>::value, "expected foo()");
187187
\end{cppcode*}
188-
\end{exampleblock}
188+
\end{exampleblockGB}
189189
\end{frame}
190190

191191
\begin{frame}[fragile]

talk/expert/variadictemplate.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
\begin{frame}[fragile]
123123
\frametitlecpp[11]{Variadic class template}
124-
\begin{block}{The tuple example, simplified - \godboltLink{https://godbolt.org/z/nxjja4bob}}
124+
\begin{exampleblockGB}{The tuple example, simplified}{https://godbolt.org/z/nxjja4bob}{\texttt{tuple} code}
125125
\begin{cppcode*}{}
126126
template <typename... Ts>
127127
struct tuple {};
@@ -136,7 +136,7 @@
136136
tuple<double, uint64_t, const char*>
137137
t1(12.2, 42, "big");
138138
\end{cppcode*}
139-
\end{block}
139+
\end{exampleblockGB}
140140
\end{frame}
141141

142142
\begin{frame}[fragile]

talk/morelanguage/lambda.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@
293293
\end{frame}
294294

295295
\begin{frame}[fragile]
296-
\frametitlecpp[11]{Higher-order lambdas \godboltLink{https://godbolt.org/z/GMj76Wer7}}
297-
\begin{exampleblock}{Example}
296+
\frametitlecpp[11]{Higher-order lambdas}
297+
\begin{exampleblockGB}{Example}{https://godbolt.org/z/GMj76Wer7}{\texttt{lambda}}
298298
\begin{cppcode*}{}
299299
auto build_incrementer = [](int inc) {
300300
return [inc](int value) { return value + inc; };
@@ -305,7 +305,7 @@
305305
i = inc1(i); // i = 1
306306
i = inc10(i); // i = 11
307307
\end{cppcode*}
308-
\end{exampleblock}
308+
\end{exampleblockGB}
309309
\begin{block}{How it works}
310310
\begin{itemize}
311311
\item \mintinline{cpp}{build_incrementer} returns a function object

talk/morelanguage/morestl.tex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
\begin{frame}[fragile]
5858
\frametitlecpp[20]{\texttt{std::span<T>} - Usage}
59-
\begin{exampleblock}{Some example - \godboltLink{https://godbolt.org/z/W81sjrbxK}}
59+
\begin{exampleblockGB}{Some example}{https://godbolt.org/z/W81sjrbxK}{\texttt{span}}
6060
\scriptsize
6161
\begin{cppcode*}{}
6262
void print(std::span<int> c) {
@@ -81,7 +81,7 @@
8181
std::cout << sizeof(sv) << " " << sizeof(sa2) << "\n"; // 16 8
8282
std::span<int, 3> s2a2 = a; // compilation failure, invalid conversion
8383
\end{cppcode*}
84-
\end{exampleblock}
84+
\end{exampleblockGB}
8585
\end{frame}
8686

8787
\begin{frame}[fragile]
@@ -185,7 +185,7 @@
185185
\end{itemize}
186186
\end{itemize}
187187
\end{block}
188-
\begin{exampleblock}{Practically \godboltLink{https://godbolt.org/z/bxzEsM3de}}
188+
\begin{exampleblockGB}{Practically}{https://godbolt.org/z/bxzEsM3de}{\texttt{variant visitor}}
189189
\small
190190
\begin{cppcode*}{gobble=2}
191191
struct Visitor {
@@ -200,17 +200,17 @@
200200
}
201201
print(100); print(42.0f); print("example"); print('A');
202202
\end{cppcode*}
203-
\end{exampleblock}
203+
\end{exampleblockGB}
204204
\end{frame}
205205

206206
\begin{frame}[fragile]
207207
\frametitlecpp[17]{std::variant and the lambda visitor pattern}
208-
\begin{exampleblock}{Idea}
208+
\begin{block}{Idea}
209209
\begin{itemize}
210210
\item use inheritance to group a set of lambdas
211211
\end{itemize}
212-
\end{exampleblock}
213-
\begin{block}{Practically \godboltLink{https://godbolt.org/z/WcdnT1hra}}
212+
\end{block}
213+
\begin{exampleblockGB}{Practically}{https://godbolt.org/z/WcdnT1hra}{\texttt{variant $\lambda$ visitor}}
214214
\small
215215
\begin{cppcode*}{gobble=2}
216216
template<typename... Ts> // covered in expert part
@@ -227,7 +227,7 @@
227227
std::visit(overloadSet, v);
228228
}
229229
\end{cppcode*}
230-
\end{block}
230+
\end{exampleblockGB}
231231
\end{frame}
232232

233233
\begin{frame}[fragile]

0 commit comments

Comments
 (0)