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

Clean up rest of part 5.

parent a275f56f
......@@ -93,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -117,31 +117,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1minput_line_10:5:10: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mcall to implicitly-deleted copy constructor of 'std::__1::unique_ptr<int, std::__1::default_delete<int> >'\u001b[0m\n",
" auto copy = ptr; // COMPILATION ERROR: can't be copied! \n",
"\u001b[0;1;32m ^ ~~~\n",
"\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/formation_cpp_2020/include/c++/v1/memory:2488:3: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcopy constructor is implicitly deleted because 'unique_ptr<int, std::__1::default_delete<int> >' has a user-declared move constructor\u001b[0m\n",
" unique_ptr(unique_ptr&& __u) _NOEXCEPT\n",
"\u001b[0;1;32m ^\n",
"\u001b[0m"
]
},
{
"ename": "Interpreter Error",
"evalue": "",
"output_type": "error",
"traceback": [
"Interpreter Error: "
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <memory>\n",
"\n",
......@@ -154,34 +132,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1minput_line_14:4:26: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mcall to implicitly-deleted copy constructor of 'std::unique_ptr<int>'\u001b[0m\n",
" std::unique_ptr<int> copy = std::move(ptr); // Ok\n",
"\u001b[0;1;32m ^ ~~~~~~~~~~~~~~\n",
"\u001b[0m"
]
},
{
"ename": "Interpreter Error",
"evalue": "",
"output_type": "error",
"traceback": [
"Interpreter Error: "
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <memory>\n",
"#include <iostream>\n",
"\n",
"{\n",
" std::unique_ptr<int> ptr = std::make_unique<int>(5);\n",
" auto copy = std::move(ptr); // Ok - or should be (recent Xeus cling doesn't concur but is wrong...)\n",
" std::cout << \"Beware as now there are no guarantee upon the content of ptr: \" << *ptr << std::endl;\n",
"}"
]
},
......@@ -189,7 +150,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As usual with move semantics, beware in this second case: ptr is undefined after the `move` occurred...\n",
"As usual with move semantics, beware in this second case: ptr is undefined after the `move` occurred... (this code run on [Coliru](http://coliru.stacked-crooked.com/a/a1aa87e64f64c9e8) leads to a segmentation fault).\n",
"\n",
"### Usage to store data in a class\n",
"\n",
......@@ -501,7 +462,7 @@
" for (double x = 0.; x < 8.; x += 1.1)\n",
" {\n",
" std::cout << \"Capacity = \" << list.capacity() << std::endl;\n",
" list.emplace_back(std::make_unique<NotCopyable>(x));\n",
" list.emplace_back(std::make_unique<NotCopyable>(x)); // emplace_back is like push_back for rvalues\n",
" }\n",
" \n",
"}"
......
......@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Getting started in C++](/) - [Useful concepts and STL](/notebooks/5-UsefulConceptsAndSTL/0-main.ipynb) - [Algorithms](/notebooks/5-UsefulConceptsAndSTL/7-Algorithms.ipynb)"
"# [Getting started in C++](/) - [Useful concepts and STL](./0-main.ipynb) - [Algorithms](./7-Algorithms.ipynb)"
]
},
{
......@@ -451,7 +451,7 @@
"\n",
"* Place at the beginning of the vector the values to be kept.\n",
"* Returns an iterator to the **logical end** of the expected series...\n",
"* But does not deallocate the memory! (and keeps the container `size()` - see below)\n",
"* But does not deallocate the memory! (and keeps the container's `size()` - see below)\n",
"\n",
"So to print the relevant values only, you should do:\n"
]
......@@ -551,7 +551,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)_"
]
......@@ -561,14 +561,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,
......
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