Commit 20e927fb authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Rewrite slightly the vector example in to remove the focus from std::vector...

Rewrite slightly the vector example in  to remove the focus from std::vector throughout the standards.
parent 254c24df
Pipeline #248518 canceled with stage
in 16 minutes and 42 seconds
......@@ -782,7 +782,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"On such trivial examples it might not seem much, but in practice it might prove incredibly useful. Consider for instance the following C++03 code (the details don't matter: we'll deal with `std::vector` in a [later notebook](../5-UsefulConceptsAndSTL/3-Containers.ipynb)):"
"On such trivial examples it might not seem much, but in practice it might prove incredibly useful. Consider for instance the following versions of the code for iterating over a vector with an 'historical' `for` loop (the details don't matter: we'll deal with `std::vector` in a [later notebook](../5-UsefulConceptsAndSTL/3-Containers.ipynb)):"
]
},
{
......@@ -795,17 +795,9 @@
"#include <iostream>\n",
"\n",
"{\n",
" // C++ 03 initialization of a std::vector\n",
" std::vector<unsigned int> primes;\n",
" primes.push_back(2);\n",
" primes.push_back(3);\n",
" primes.push_back(5);\n",
" primes.push_back(7); \n",
" primes.push_back(11);\n",
" primes.push_back(13); \n",
" primes.push_back(17); \n",
" primes.push_back(19); \n",
" std::vector<unsigned int> primes { 2, 3, 5 };\n",
"\n",
" // C++ 03 way of iterating over the content of a vector.\n",
" for (std::vector<unsigned int>::const_iterator it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
......@@ -834,15 +826,16 @@
"#include <iostream>\n",
"\n",
"{\n",
" std::vector<unsigned int> primes { 2, 3, 5, 7, 11, 13, 17, 19 }; // I'm cheating this time with C++ 11 notation...\n",
" using iterator = std::vector<unsigned int>::const_iterator;\n",
" std::vector<unsigned int> primes { 2, 3, 5 };\n",
" using iterator = std::vector<unsigned int>::const_iterator;\n",
" \n",
" for (iterator it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
" {\n",
" std::cout << *it << \" is prime.\" << std::endl;\n",
" }\n",
" // C++ 03 way of iterating over the content of a vector - with an alias\n",
" for (iterator it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
" {\n",
" std::cout << *it << \" is prime.\" << std::endl;\n",
" }\n",
"}\n"
]
},
......@@ -863,14 +856,15 @@
"#include <iostream>\n",
"\n",
"{\n",
" std::vector<unsigned int> primes { 2, 3, 5, 7, 11, 13, 17, 19 }; // I'm cheating: it's C++ 11 notation...\n",
" std::vector<unsigned int> primes { 2, 3, 5 };\n",
" \n",
" for (decltype(primes.cbegin()) it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
" {\n",
" std::cout << *it << \" is prime.\" << std::endl;\n",
" }\n",
" // C++ 11 decltype\n",
" for (decltype(primes.cbegin()) it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
" {\n",
" std::cout << *it << \" is prime.\" << std::endl;\n",
" }\n",
"}"
]
},
......@@ -891,8 +885,9 @@
"#include <iostream>\n",
"\n",
"{\n",
" std::vector<unsigned int> primes { 2, 3, 5, 7, 11, 13, 17, 19 }; // I'm cheating: it's C++ 11 notation...\n",
" std::vector<unsigned int> primes { 2, 3, 5 };\n",
" \n",
" // C++ 11 auto\n",
" for (auto it = primes.cbegin();\n",
" it != primes.cend();\n",
" ++it)\n",
......
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