Commit d5c847ae authored by CHAMONT David's avatar CHAMONT David
Browse files

Ajout des videos, un peu de reorganisation, dernieres traductions.

parent 6971165c
...@@ -31,7 +31,16 @@ ...@@ -31,7 +31,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -90,7 +99,7 @@ ...@@ -90,7 +99,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -143,7 +152,7 @@ ...@@ -143,7 +152,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -152,7 +161,7 @@ ...@@ -152,7 +161,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
......
...@@ -8,20 +8,16 @@ ...@@ -8,20 +8,16 @@
* Main lecturer : [David Chamont](https://discourse.lal.in2p3.fr/u/david/) (CNRS, IJCLab) * Main lecturer : [David Chamont](https://discourse.lal.in2p3.fr/u/david/) (CNRS, IJCLab)
* Helper and translater : [Karim Hasnaoui](https://discourse.lal.in2p3.fr/u/hasnaoui/summary) (CNRS, IDRIS) * Helper and translater : [Karim Hasnaoui](https://discourse.lal.in2p3.fr/u/hasnaoui/summary) (CNRS, IDRIS)
## Who are the trainees ? ## Quizz
Live only.
## Forum check-list ## Who are the trainees ?
* Have you created your account on the [LAL Discourse forum](https://discourse.lal.in2p3.fr/) ? * Have you created your account on the [LAL Discourse forum](https://discourse.lal.in2p3.fr/) ?
* Did you fill your profile ? ( Top right / Preferences / Preferences / Profile / About me ) * Did you fill your profile ? ( Top right / Preferences / Preferences / Profile / About me )
* Do you watch the category [“2021 - Scientific Modern C++”](https://discourse.lal.in2p3.fr/c/formation/2021-scientific-modern-cpp/) ? ( Select the bell on the right ) * Do you watch the category [“2021 - Scientific Modern C++”](https://discourse.lal.in2p3.fr/c/formation/2021-scientific-modern-cpp/) ? ( Select the bell on the right )
## Quizz
Live only.
## Exercise ## Exercise
As a warm-up, we suggest you try an exercise using the web compiler [CoLiRu](http://coliru.stacked-crooked.com/) (use the `-std=c++03` option). As a warm-up, we suggest you try an exercise using the web compiler [CoLiRu](http://coliru.stacked-crooked.com/) (use the `-std=c++03` option).
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
" << std::numeric_limits<float>::min() << '\\t'\n", " << std::numeric_limits<float>::min() << '\\t'\n",
" << std::numeric_limits<float>::max() << '\\n' \n", " << std::numeric_limits<float>::max() << '\\n' \n",
" << \"double\\t\" << sizeof(double) << \"\\t\\t\"\n", " << \"double\\t\" << sizeof(double) << \"\\t\\t\"\n",
" << std::numeric_limits<double>::min() << '\\t'\n", " << std::numeric_limits<double>::min() << '\\t' \n",
" << std::numeric_limits<double>::max() << '\\n' ;" " << std::numeric_limits<double>::max() << '\\n' ;"
] ]
}, },
...@@ -516,7 +516,7 @@ ...@@ -516,7 +516,7 @@
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "subslide"
} }
}, },
"outputs": [], "outputs": [],
...@@ -630,7 +630,7 @@ ...@@ -630,7 +630,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "skip"
} }
}, },
"source": [ "source": [
...@@ -645,7 +645,7 @@ ...@@ -645,7 +645,7 @@
} }
}, },
"source": [ "source": [
"A more complex but flexible approach: make anything a template, with the floating type as parameter. This allows to use some different types anywhere you need." "A more flexible approach: make anything a template, with the floating type as parameter. This allows to mix different types within an application."
] ]
}, },
{ {
...@@ -726,7 +726,20 @@ ...@@ -726,7 +726,20 @@
" public :\n", " public :\n",
" Half( double f ) { std::cout<<\"construct\"<<std::endl ; }\n", " Half( double f ) { std::cout<<\"construct\"<<std::endl ; }\n",
" operator double() { std::cout<<\"convert\"<<std::endl ; return 0 ; }\n", " operator double() { std::cout<<\"convert\"<<std::endl ; return 0 ; }\n",
" } ;" " } ; "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": [
"void display_double( double ) { std::cout<<\"display double\"<<std::endl ; }"
] ]
}, },
{ {
...@@ -739,8 +752,7 @@ ...@@ -739,8 +752,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"void display( double )\n", "void display_half( Half ) { std::cout<<\"display half\"<<std::endl ; }"
" { std::cout<<\"display\"<<std::endl ; }"
] ]
}, },
{ {
...@@ -754,7 +766,8 @@ ...@@ -754,7 +766,8 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"Half value = 3.14 ;\n", "Half value = 3.14 ;\n",
"display(value) ;" "display_double(value) ;\n",
"display_half(3.14) ;"
] ]
}, },
{ {
...@@ -778,8 +791,8 @@ ...@@ -778,8 +791,8 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"void display2( short )\n", "void display_short( short )\n",
" { std::cout<<\"display2\"<<std::endl ; }" " { std::cout<<\"display_short\"<<std::endl ; }"
] ]
}, },
{ {
...@@ -793,7 +806,7 @@ ...@@ -793,7 +806,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"Half value = 42 ;\n", "Half value = 42 ;\n",
"display2(value) ;" "display_short(value) ;"
] ]
}, },
{ {
...@@ -814,7 +827,7 @@ ...@@ -814,7 +827,7 @@
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "subslide"
} }
}, },
"outputs": [], "outputs": [],
...@@ -833,7 +846,7 @@ ...@@ -833,7 +846,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"class Half\n", "class Half\n",
" {\n", " { \n",
" public :\n", " public :\n",
" explicit Half( double f ) { std::cout<<\"construct\"<<std::endl ; }\n", " explicit Half( double f ) { std::cout<<\"construct\"<<std::endl ; }\n",
" operator double() { std::cout<<\"convert\"<<std::endl ; return 0 ; }\n", " operator double() { std::cout<<\"convert\"<<std::endl ; return 0 ; }\n",
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"void check( Derived obj )\n", "void check( Derived obj )\n",
" {\n", " { \n",
" obj.display(42) ;\n", " obj.display(42) ;\n",
" obj.display(3.14f) ;\n", " obj.display(3.14f) ;\n",
" obj.display(3.14) ;\n", " obj.display(3.14) ;\n",
...@@ -294,7 +294,7 @@ ...@@ -294,7 +294,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -325,7 +325,7 @@ ...@@ -325,7 +325,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -405,7 +405,7 @@ ...@@ -405,7 +405,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "subslide" "slide_type": "subslide"
...@@ -418,7 +418,7 @@ ...@@ -418,7 +418,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -438,21 +438,13 @@ ...@@ -438,21 +438,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
} }
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 2 4 6 8 10 12 14 16 18 "
]
}
],
"source": [ "source": [
"LinearFunction times2(2) ;\n", "LinearFunction times2(2) ;\n",
"const int SIZE = 10 ;\n", "const int SIZE = 10 ;\n",
...@@ -487,7 +479,7 @@ ...@@ -487,7 +479,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -500,7 +492,7 @@ ...@@ -500,7 +492,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -522,21 +514,13 @@ ...@@ -522,21 +514,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
} }
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 2 4 6 8 10 12 14 16 18 "
]
}
],
"source": [ "source": [
"const int SIZE = 10 ;\n", "const int SIZE = 10 ;\n",
"double values[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;\n", "double values[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;\n",
...@@ -556,7 +540,7 @@ ...@@ -556,7 +540,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 45, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
...@@ -576,21 +560,13 @@ ...@@ -576,21 +560,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "-" "slide_type": "-"
} }
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 2 4 6 8 10 12 14 16 18 "
]
}
],
"source": [ "source": [
"const int SIZE = 10 ;\n", "const int SIZE = 10 ;\n",
"double values[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;\n", "double values[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;\n",
......
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
" return res ; \n", " return res ; \n",
" }\n", " }\n",
"\n", "\n",
"template< typename T, int n >\n", "template< typename T, int n > \n",
"struct Array\n", "struct Array\n",
" {\n", " {\n",
" T data[n] ;\n", " T data[n] ;\n",
...@@ -815,7 +815,7 @@ ...@@ -815,7 +815,7 @@
"template<typename Val>\n", "template<typename Val>\n",
"struct MyContainer\n", "struct MyContainer\n",
" {\n", " {\n",
" int size() { return 0 } ;\n", " int size() { return 0 ; } ;\n",
" } ;" " } ;"
] ]
}, },
...@@ -1039,6 +1039,8 @@ ...@@ -1039,6 +1039,8 @@
"source": [ "source": [
"%%file tmp.equal.h\n", "%%file tmp.equal.h\n",
"\n", "\n",
"#include \"tmp.traits.h\"\n",
"\n",
"template<typename T>\n", "template<typename T>\n",
"bool equal( T e1, T e2 )\n", "bool equal( T e1, T e2 )\n",
" { return (e1==e2) ; }\n", " { return (e1==e2) ; }\n",
...@@ -1064,7 +1066,6 @@ ...@@ -1064,7 +1066,6 @@
"source": [ "source": [
"%%file tmp.templates.cpp\n", "%%file tmp.templates.cpp\n",
"\n", "\n",
"#include \"tmp.properties.h\"\n",
"#include \"tmp.equal.h\"\n", "#include \"tmp.equal.h\"\n",
"\n", "\n",
"template<typename T>\n", "template<typename T>\n",
...@@ -1152,7 +1153,7 @@ ...@@ -1152,7 +1153,7 @@
" \n", " \n",
"template<typename T>\n", "template<typename T>\n",
"bool equal( T e1, T e2 )\n", "bool equal( T e1, T e2 )\n",
" { return abs(e1-e2)<Properties<T>::epsilon ; }" " { return abs(e1-e2)<Traits<T>::epsilon ; }"
] ]
}, },
{ {
...@@ -1167,7 +1168,6 @@ ...@@ -1167,7 +1168,6 @@
"source": [ "source": [
"%%file tmp.templates.cpp\n", "%%file tmp.templates.cpp\n",
"\n", "\n",
"#include \"tmp.properties.h\"\n",
"#include \"tmp.equal.h\"\n", "#include \"tmp.equal.h\"\n",
"\n", "\n",
"template<typename T>\n", "template<typename T>\n",
...@@ -1221,7 +1221,7 @@ ...@@ -1221,7 +1221,7 @@
} }
}, },
"source": [ "source": [
"When compiling `compare(100,10*10)`, because those literals are `int`, the compiler chose the template flavor of `equal`, which can better match `int` than the `equal` function using `unsigned`. Then, during instanciation of the template flavor of `equal`, it fails to fin `Properties<int>::epsilon`." "When compiling `compare(100,10*10)`, because those literals are `int`, the compiler chose the template flavor of `equal`, which can better match `int` than the `equal` function using `unsigned`. Then, during instanciation of the template flavor of `equal`, it fails to fin `Traits<int>::epsilon`."
] ]
}, },
{ {
...@@ -1232,9 +1232,9 @@ ...@@ -1232,9 +1232,9 @@
} }
}, },
"source": [ "source": [
"It's one of the biggest historical limitations of templates: **we have no direct way to impose constraints on parameters**. In our example, there is no easy way to explain to the compiler that the template flavor of `equal` should only be used if `Properties<T>::epsilon` exists.\n", "It's one of the biggest historical limitations of templates: **we have no direct way to impose constraints on parameters**. In our example, there is no easy way to explain to the compiler that the template flavor of `equal` should only be used if `Traits<T>::epsilon` exists.\n",
"\n", "\n",
"We have complicated indirect ways, within the frame of Template Meta Programming : *SIFNAE*, `enable_if`... which we will not address here. Hopefully, C++20 bring new features, called **Concepts**, which solve this issue." "We have complicated indirect ways, within the frame of Template Meta Programming : *SFINAE*, `enable_if`... which we will not address here. Hopefully, C++20 bring new features, called **Concepts**, which solve this issue."
] ]
}, },
{ {
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#include <vector>\n",
"#include <list>\n",
"std::map<std::vector<int>,std::list<float>> m ;\n", "std::map<std::vector<int>,std::list<float>> m ;\n",
"auto itr = m.begin() ;" "auto itr = m.begin() ;"
] ]
...@@ -367,7 +369,7 @@ ...@@ -367,7 +369,7 @@
"double values[MAX] = { 1.1, 2.2, 3.3, 4.4, 5.5 } ;\n", "double values[MAX] = { 1.1, 2.2, 3.3, 4.4, 5.5 } ;\n",
"for ( double & value : values )\n", "for ( double & value : values )\n",
" { value *= 2 ; }\n", " { value *= 2 ; }\n",
"for ( double value : values )\n", "for ( double value : values ) \n",
" { std::cout<<value<<\" \" ; }\n", " { std::cout<<value<<\" \" ; }\n",
"std::cout<<std::endl ;" "std::cout<<std::endl ;"
] ]
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"source": [ "source": [
"# Modern C++ : uniform initialization?\n", "# Modern C++ : uniform initialization?\n",
"\n", "\n",
"The history of the language and the desire for backward compatibility have led to multiple ways of initializing variables and objects. This confuses the programmer, harms the readability of the code, and ** implies problems in the use of templates **." "The history of the language and the desire for backward compatibility have led to multiple ways of initializing variables and objects. This confuses the programmer, harms the readability of the code, and **implies problems in the use of templates**."
] ]
}, },
{ {
...@@ -250,8 +250,8 @@ ...@@ -250,8 +250,8 @@
"\n", "\n",
"auto params = { 1, 2, 3, 4, 5 } ;\n", "auto params = { 1, 2, 3, 4, 5 } ;\n",
"for ( int param : params )\n", "for ( int param : params )\n",
" { std::cout<<param<<\" \" ; }\n", " { std::cout << param <<