Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parallel STL course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michaël El Kharroubi
Parallel STL course
Commits
fda801e0
Commit
fda801e0
authored
1 year ago
by
Michaël El Kharroubi
Browse files
Options
Downloads
Patches
Plain Diff
[WIP] Working on lambda and captures
parent
77b0eab7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cpp_basics_for_STL.typ
+57
-1
57 additions, 1 deletion
cpp_basics_for_STL.typ
intro.typ
+1
-1
1 addition, 1 deletion
intro.typ
with
58 additions
and
2 deletions
cpp_basics_for_STL.typ
+
57
−
1
View file @
fda801e0
...
...
@@ -220,7 +220,63 @@ delete[] ptr;
```
]
#new-section-slide(
"
Closures
"
)
#new-section-slide(
"
Lambda
&
captures
"
)
#slide(
title:
"
Les
fonctions
anonymes
"
,
)[
De plus en plus de langages proposent un mechanisme pour écrire des fonctions
anonymes, aussi appelées expressions lambda.
Depuis C++ 11, il existe un moyen d'écrire des fonctions lambda. La syntaxe
simplifiée d'une lambda en C++ est la suivante : ```cpp
[captures](paramètres){corps de la fonction}
```
Si je veux par exemple définir une fonction qui multiplie un entier par 2, je
peux écrire : ```cpp
auto times_two = [](int i){return 2*i;};
int x = times_two(3); // x vaut 6
```
]
#slide(
title:
"
Les
captures
"
,
)[
Les expressions lambda en C++ peuvent capturer leur environnement.
Si je souhaite par exemple ajouter une constante à en entier, je peux écrire :
```cpp
int cst = 5;
auto add_cst = [cst](int i){ return i+cst;};
int x = add_cst(10); // x vaut 15
```
]
#slide(title:
"
Les
types
de
captures
"
)[
Il existe deux moyens de capturer une variable :
#box(columns(2, gutter: 22pt)[
== Par copie
```cpp
int var = 5;
auto add_cst = [v=var](int i)
{ return i+v; };
var = 2;
int x = add_cst(10); // x vaut 15
```
#colbreak()
== Par référence
```cpp
int var = 5;
auto add_cst = [v=&var](int i)
{ return i+v;};
var = 2;
int x = add_cst(10); // x vaut 12
```
])
]
#new-section-slide(
"
Algorithmes
STL
"
)
...
...
This diff is collapsed.
Click to expand it.
intro.typ
+
1
−
1
View file @
fda801e0
...
...
@@ -44,7 +44,7 @@
+
La
gestion
de
la
m
é
moire
en
GPGPU
#
pause
+
Les
it
é
rateurs
C
++
+
Les
vecteurs
,
les
tableaux
et
les
spans
+
Les
captures
+
Les
lambda
&
captures
+
Les
algorithmes
de
la
Standard
Template
Library
(
STL
)
#
pause
+
Pr
é
sentation
du
kit
HPC
Nvidia
+
Le
compilateur
nvc
++
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment