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
a4f429bc
Commit
a4f429bc
authored
1 year ago
by
Michaël El Kharroubi
Browse files
Options
Downloads
Patches
Plain Diff
cpp basics done
parent
06d7d0fc
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpp_basics_for_STL.typ
+46
-10
46 additions, 10 deletions
cpp_basics_for_STL.typ
with
46 additions
and
10 deletions
cpp_basics_for_STL.typ
+
46
−
10
View file @
a4f429bc
...
...
@@ -342,8 +342,7 @@ std::cout << is_sorted << std::endl;
std::vector<int> v = {6, 3, 4, 12, 1, 15};
std::vector<std::string> parity{6};
std::transform(v.begin(),
v.end(),
std::transform(v.begin(), v.end(),
parity.begin(),
[](int i){
std::string s = (i % 2) == 0 ?
"
even
"
:
"
odd
"
;
...
...
@@ -360,21 +359,58 @@ std::cout << std::endl;
#slide(title:
"
Exemple
de
reduction
"
)[
```cpp
constexpr int kN = 100;
std::vector<int> v
{
kN, 0
}
;
std::vector<int> v
(
kN, 0
)
;
std::iota(v.begin(), v.end(), 1);
int sum = std::accumulate(v.begin(),
v.end(),
0,
[](int acc, int i){
return acc + i;
});
int sum = std::accumulate(v.begin(), v.end(),
0,
[](int acc, int i){
return acc + i;
});
std::cout << sum << std::endl;
bool sum_correct = sum == (kN*(kN+1))/2;
std::cout << sum_correct << std::endl;
```
]
#slide(title:
"
Exemple
de
suppression
conditionnelle
(
filter
)
"
)[
```cpp
std::vector<int> v = {6, 3, 4, 12, 1, 15};
auto last = std::remove_if(v.begin(), v.end(),
[](int i){
return (i % 2) == 1;
});
size_t filtered_size = std::distance(v.begin(), last);
v.resize(filtered_size);
for (int i : v){
std::cout << i <<
"
"
;
}
std::cout << std::endl;
```
]
#new-section-slide(
"
Notions
à
retenir
"
)
#slide(
title:
"
Notions
essentielles
à
retenir
"
,
)[
- Les collections proposent un itérateur sur le début et la fin avec les méthodes
`begin` et `end`
- Un `std::vector` est un tableau de taille dynamique
- Un `std::array` est un tableau statique
- Si l'on est pas responsable des données, il faut utiliser un `std::span`
- Les lambdas sont des fonctions anonymes qui peuvent capturer totalement ou
partiellement leur environnement
- On peut capturer par référence ou par copie
- Les algorithmes STL à connaître sont :
- `iota`
- `transform`
- `accumulate`
- `remove_if`
]
#new-section-slide(
"
Questions
?
"
)
\ No newline at end of file
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