Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit a0962558 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Cleaning-up operators part.

parent 26964ec1
......@@ -4,21 +4,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Operators](/notebooks/3-Operators/0-main.ipynb)"
"# [Getting started in C++](/) - [Operators](./0-main.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* [Introduction to the concept of operator overload](/notebooks/3-Operators/1-Intro.ipynb)\n",
" * [TP 9](/notebooks/3-Operators/1b-TP.ipynb)\n",
"* [Comparison operators](/notebooks/3-Operators/2-Comparison.ipynb)\n",
"* [Stream operators](/notebooks/3-Operators/3-Stream.ipynb)\n",
" * [TP 10](/notebooks/3-Operators/3b-TP.ipynb)\n",
"* [Affectation operator and the canonical form of a class](/notebooks/3-Operators/4-CanonicalForm.ipynb)\n",
"* [Functors](/notebooks/3-Operators/5-Functors.ipynb)\n",
" * [TP 11](/notebooks/3-Operators/5b-TP.ipynb)"
"* [Introduction to the concept of operator overload](./1-Intro.ipynb)\n",
" * [TP 9](./1b-TP.ipynb)\n",
"* [Comparison operators](./2-Comparison.ipynb)\n",
"* [Stream operators](./3-Stream.ipynb)\n",
" * [TP 10](./3b-TP.ipynb)\n",
"* [Affectation operator and the canonical form of a class](./4-CanonicalForm.ipynb)\n",
"* [Functors](./5-Functors.ipynb)\n",
" * [TP 11](./5b-TP.ipynb)"
]
},
{
......@@ -26,7 +26,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -36,14 +36,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -83,5 +83,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Operators](/notebooks/3-Operators/0-main.ipynb) - [Introduction](/notebooks/3-Operators/1-Intro.ipynb)"
"# [Getting started in C++](/) - [Operators](./0-main.ipynb) - [Introduction](./1-Intro.ipynb)"
]
},
{
......@@ -535,8 +535,8 @@
"\n",
"````\n",
"= \n",
". -> .* ->*\n",
"new delete sizeof\n",
"-> ->*\n",
"new delete\n",
"\n",
"````\n",
"\n",
......@@ -651,7 +651,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -661,14 +661,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -703,5 +703,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Operators](/notebooks/3-Operators/0-main.ipynb) - [Comparison operators](/notebooks/3-Operators/2-Comparison.ipynb)"
"# [Getting started in C++](/) - [Operators](./0-main.ipynb) - [Comparison operators](./2-Comparison.ipynb)"
]
},
{
......@@ -90,7 +90,7 @@
"\n",
"* `operator>(lhs, rhs)` is `operator<(rhs, lhs)`\n",
"* `operator>=(lhs, rhs)` is `!operator<(lhs, rhs)`\n",
"* `operator<=(lhs, rhs)` is `!operator<(rhs, lhs)`\n",
"* `operator<=(lhs, rhs)` is `!operator>(rhs, lhs)`\n",
"\n",
"\n",
"As always with operators overloading, make sure your implementation is consistent: it's not because you might define an operator `<` which is not the negation of `>=` that you should do it!\n",
......@@ -187,7 +187,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -197,14 +197,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -239,5 +239,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Operators](/notebooks/3-Operators/0-main.ipynb) - [Stream operators](/notebooks/3-Operators/3-Stream.ipynb)"
"# [Getting started in C++](/) - [Operators](./0-main.ipynb) - [Stream operators](./3-Stream.ipynb)"
]
},
{
......@@ -14,14 +14,14 @@
},
"source": [
"<h1>Table of contents<span class=\"tocSkip\"></span></h1>\n",
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Operators-<<\" data-toc-modified-id=\"Operators-<<-1\">Operators &lt;&lt;</a></span></li><li><span><a href=\"#Operator>>\" data-toc-modified-id=\"Operator>>-2\">Operator&gt;&gt;</a></span></li></ul></div>"
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Operator-<<\" data-toc-modified-id=\"Operator-<<-1\">Operator &lt;&lt;</a></span></li><li><span><a href=\"#Operator->>\" data-toc-modified-id=\"Operator->>-2\">Operator &gt;&gt;</a></span></li></ul></div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Operators <<\n",
"## Operator <<\n",
"\n",
"So far, we have very often defined methods and/or functions named `Print()` to provide a visual printing of the content of a class.\n",
"\n",
......@@ -72,7 +72,7 @@
"\n",
"std::ostream& operator<<(std::ostream& out, const Rational& r)\n",
"{\n",
" r.Print(out); // see how the buk of the work is done by the 'Print()' method!\n",
" r.Print(out); // see how the bulk of the work is done by the 'Print()' method!\n",
" return out;\n",
"}\n",
"\n",
......@@ -120,7 +120,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Operator>>\n",
"## Operator >>\n",
"\n",
"Operator>> might be overloaded in a similar way; it might be used for instance to create an object from data readin a file. As usual with `operator>>`, you should be cautious and handle well the case in which the flux becomes invalid:"
]
......@@ -241,7 +241,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -251,14 +251,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -298,5 +298,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -291,7 +291,7 @@
"source": [
"### Uncopyable class\n",
"\n",
"In fact when I said by default an affectation operator is made available for the class, I was overly simplifying the issue. Lets consider for instance a class with a reference data attribute:"
"In fact when I said by default an affectation operator is made available for the class, I was overly simplifying the issue. Let's consider for instance a class with a reference data attribute:"
]
},
{
......@@ -436,10 +436,10 @@
"Copy construction may in fact be quite dangerous:\n",
"\n",
"* As we've just seen, affectation and construction may differ in implementation, which is not a good thing. There are ways to define one in function of the other (see for instance item 11 of \\cite{Meyers2005}) but they aren't that trivial.\n",
"* Depending on complicated rules, some might or might not be defined implicitly.\n",
"* Depending on somewhat complicated rules that have evolved with standard versions, some might or might not be defined implicitly.\n",
"* More importantly, affectation operators may be a nightmare to maintain. Imagine you have a class for which you overload manually the affectation operator and/or the copy constructor. If later you add a new data attribute, you have to make sure not to forget to add it in both implementations; if you forget once you will enter the real of undefined behaviour... and good luck for you to find the origin of the bug!\n",
"\n",
"To avoid that I took the extreme rule to never overload those myself:\n",
"To avoid that I took the extreme rule to (almost) never overload those myself:\n",
"\n",
"* As explained briefly above, using appropriate container may remove the need. `Vector3` could be written with a `std::array` instead of the dynamic array, and the STL object will be properly copied with default behaviour!\n",
"* I define explicitly in my classes the behaviour of these operators with `= default` or `= delete` syntaxes. More often than not, my objects have no business being copied and `= delete` is really my default choice (this keyword indicates to the compiler the operator should not be provided for the class).\n",
......@@ -550,7 +550,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -560,14 +560,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -602,5 +602,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Operators](/notebooks/3-Operators/0-main.ipynb) - [Functors](/notebooks/3-Operators/5-Functors.ipynb)"
"# [Getting started in C++](/) - [Operators](./0-main.ipynb) - [Functors](./5-Functors.ipynb)"
]
},
{
......@@ -94,7 +94,7 @@
"\n",
"## Functors in STL\n",
"\n",
"STL itself defines some functors: imagine you want to sort a `std::vector` decreasingly; you can't directly put `>` as the comparison operation in sort and use the STL-defined `greater`: "
"STL itself defines some functors: imagine you want to sort a `std::vector` decreasingly; you can't directly put `>` as the comparison operation in `sort` and therefore may use a specific STL-defined `greater`: "
]
},
{
......@@ -121,7 +121,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"C++ 11 and above limits the need for functors with lambda functions, but in older codes functors were one of the way to pass your own rules to some STL algorithms, along with pointer to functions."
"C++ 11 and above limits the need for functors with lambda functions (see [earlier](../1-ProceduralProgramming/4-Functions.ipynb#Lambda-functions)), but in older codes functors were one of the way to pass your own rules to some STL algorithms, along with pointer to functions."
]
},
{
......@@ -129,7 +129,7 @@
"metadata": {},
"source": [
"\n",
"© _CNRS 2016_ - _Inria 2018-2019_ \n",
"© _CNRS 2016_ - _Inria 2018-2020_ \n",
"_This notebook is an adaptation of a lecture prepared by David Chamont (CNRS) under the terms of the licence [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](http://creativecommons.org/licenses/by-nc-sa/4.0/)_ \n",
"_The present version has been written by Sébastien Gilles and Vincent Rouvreau (Inria)_"
]
......@@ -139,14 +139,14 @@
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xeus-cling-cpp17"
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "-std=c++17"
"version": "17"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......@@ -181,5 +181,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment