From e924f03a554b1793ff410ec395bcae48d346f0f4 Mon Sep 17 00:00:00 2001 From: Marcus Mohr <marcus.mohr@lmu.de> Date: Mon, 29 Nov 2021 17:23:38 +0100 Subject: [PATCH] Adds a remark on obtaining iterators via free functions --- notebooks/06_STL.ipynb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/notebooks/06_STL.ipynb b/notebooks/06_STL.ipynb index 644d31f..a1179e0 100644 --- a/notebooks/06_STL.ipynb +++ b/notebooks/06_STL.ipynb @@ -1110,6 +1110,45 @@ "}" ] }, + { + "cell_type": "markdown", + "id": "da22b078", + "metadata": {}, + "source": [ + "#### 'Free Functions'\n", + "C++ introduced free-function forms of ```begin()``` and ```end()``` which we can use alternatively to the member functions above:" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "ceb3de09", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "5\n", + "6\n" + ] + } + ], + "source": [ + "for( cIter it = begin( lc ), e = end( lc ); it != e; it++ ) {\n", + " std::cout << *it << std::endl;\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "14632b71", + "metadata": {}, + "source": [ + "Why did we introduce ```e```? Is it necessary?" + ] + }, { "cell_type": "markdown", "id": "c731df99", -- GitLab