diff --git a/4-Templates/0-main.ipynb b/4-Templates/0-main.ipynb index b86e105b0c2d9515ec2d34e9ed91a7fa32d851e9..b611eeffcce73c8866b585831e6cec40713eba68 100644 --- a/4-Templates/0-main.ipynb +++ b/4-Templates/0-main.ipynb @@ -4,20 +4,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "* [Introduction to the concept of templates](/notebooks/4-Templates/1-Intro.ipynb)\n", - " * [TP 12](/notebooks/4-Templates/1b-TP.ipynb)\n", - "* [Specialization](/notebooks/4-Templates/2-Specialization.ipynb)\n", - "* [Special syntax: typename, template and mandatory this](/notebooks/4-Templates/3-Syntax.ipynb)\n", - " * [TP 13](/notebooks/4-Templates/3b-TP.ipynb)\n", - "* [Metaprogramming](/notebooks/4-Templates/4-Metaprogramming.ipynb)\n", - "* [Hints to more advanced concepts with templates](/notebooks/4-Templates/5-MoreAdvanced.ipynb)" + "* [Introduction to the concept of templates](./1-Intro.ipynb)\n", + " * [TP 12](./1b-TP.ipynb)\n", + "* [Specialization](./2-Specialization.ipynb)\n", + "* [Special syntax: typename, template and mandatory this](./3-Syntax.ipynb)\n", + " * [TP 13](./3b-TP.ipynb)\n", + "* [Metaprogramming](./4-Metaprogramming.ipynb)\n", + "* [Hints to more advanced concepts with templates](./5-MoreAdvanced.ipynb)" ] }, { @@ -25,7 +25,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)_" ] @@ -35,14 +35,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, @@ -77,5 +77,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/4-Templates/1-Intro.ipynb b/4-Templates/1-Intro.ipynb index 711c1bfd3a438a5405931cdec4786f4d01fe3d82..2912a9a2a8495563211fcad59adb339ed22997c6 100644 --- a/4-Templates/1-Intro.ipynb +++ b/4-Templates/1-Intro.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb) - [Introduction](/notebooks/4-Templates/1-Intro.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb) - [Introduction](./1-Intro.ipynb)" ] }, { @@ -28,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -64,9 +64,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-8\n", + "-8\n", + "-8\n" + ] + } + ], "source": [ "#include <iostream>\n", "\n", @@ -90,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -103,9 +113,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-8\n", + "-8\n", + "-8\n", + "-8\n" + ] + } + ], "source": [ "#include <iostream>\n", "\n", @@ -129,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -142,9 +163,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_16:3:5: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno matching function for call to 'Convert'\u001b[0m\n", + " Convert(5); // Error: can't figure out which type `T` to use!\n", + "\u001b[0;1;32m ^~~~~~~\n", + "\u001b[0m\u001b[1minput_line_15:2:3: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument 'T'\u001b[0m\n", + "T Convert(int value)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "{\n", " Convert(5); // Error: can't figure out which type `T` to use!\n", @@ -153,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -171,9 +214,95 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_15:4:12: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno matching conversion for static_cast from 'int' to 'std::__1::basic_string<char>'\u001b[0m\n", + " return static_cast<T>(value);\n", + "\u001b[0;1;32m ^~~~~~~~~~~~~~~~~~~~~\n", + "\u001b[0m\u001b[1minput_line_19:3:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'Convert<std::__1::basic_string<char> >' requested here\u001b[0m\n", + " Convert<std::string>(5); // Doesn't make sense so compiler will yell!\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:792:40: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: no known conversion from 'int' to 'const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::allocator_type' (aka 'const std::__1::allocator<char>') for 1st\n", + " argument\u001b[0m\n", + " _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:799:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: no known conversion from 'int' to 'const std::__1::basic_string<char>' for 1st argument\u001b[0m\n", + " basic_string(const basic_string& __str);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:804:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: no known conversion from 'int' to 'std::__1::basic_string<char>' for 1st argument\u001b[0m\n", + " basic_string(basic_string&& __str)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:819:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: no known conversion from 'int' to 'const char *' for 1st argument\u001b[0m\n", + " basic_string(const _CharT* __s) {\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:873:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: no known conversion from 'int' to 'initializer_list<char>' for 1st argument\u001b[0m\n", + " basic_string(initializer_list<_CharT> __il);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:859:18: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: requirement '__can_be_converted_to_string_view<char, char_traits<char>, int>::value' was not satisfied [with _Tp = int]\u001b[0m\n", + " explicit basic_string(const _Tp& __t);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:831:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const _CharT* __s, const _Allocator& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:844:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires 3 arguments, but 1 was provided\u001b[0m\n", + " basic_string(size_type __n, _CharT __c, const _Allocator& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:854:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires at least 3 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const _Tp& __t, size_type __pos, size_type __n,\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:863:18: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " explicit basic_string(const _Tp& __t, const allocator_type& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:867:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(_InputIterator __first, _InputIterator __last);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:870:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor template not viable: requires 3 arguments, but 1 was provided\u001b[0m\n", + " basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:789:31: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 0 arguments, but 1 was provided\u001b[0m\n", + " _LIBCPP_INLINE_VISIBILITY basic_string()\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:800:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const basic_string& __str, const allocator_type& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:812:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(basic_string&& __str, const allocator_type& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:834:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const _CharT* __s, size_type __n);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:838:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(size_type __n, _CharT __c);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:875:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(initializer_list<_CharT> __il, const _Allocator& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:836:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires 3 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:849:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires at least 2 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const basic_string& __str, size_type __pos,\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/string:846:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor not viable: requires at least 3 arguments, but 1 was provided\u001b[0m\n", + " basic_string(const basic_string& __str, size_type __pos, size_type __n,\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "#include <string>\n", "\n", @@ -188,12 +317,12 @@ "source": [ "### `static_assert`\n", "\n", - "Of course, it would be nicer to get a clearer error message when an impossible type is provided... C++ 20 should introduce the [concept](https://en.cppreference.com/w/cpp/language/constraints) to constraint properly which type is acceptable, but C++ 11 already introduced a way slightly better than C++ 03 with `static_assert`:" + "Of course, it would be nicer to get a clearer error message when an impossible type is provided... C++ 20 will introduce the [concept](https://en.cppreference.com/w/cpp/language/constraints) to constraint properly which type is acceptable, but C++ 11 already introduced a way slightly better than C++ 03 with `static_assert`:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -209,9 +338,38 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "In file included from input_line_1:1:\n", + "In file included from /Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/new:90:\n", + "In file included from /Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/exception:80:\n", + "In file included from /Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/cstddef:110:\n", + "\u001b[1m/Users/Shared/Software/miniconda3/envs/test2/include/c++/v1/type_traits:1004:56: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno member named 'value' in 'std::__1::is_integral<std::__1::basic_string<char> >'\u001b[0m\n", + " : public integral_constant<bool, is_integral<_Tp>::value ||\n", + "\u001b[0;1;32m ~~~~~~~~~~~~~~~~~~^\n", + "\u001b[0m\u001b[1minput_line_21:4:19: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of template class 'std::__1::is_arithmetic<std::__1::basic_string<char> >' requested here\u001b[0m\n", + " static_assert(std::is_arithmetic<T>(), \"T must be an integer or a floating point!\");\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_23:3:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'Convert2<std::__1::basic_string<char> >' requested here\u001b[0m\n", + " Convert2<std::string>(5); // Doesn't make sense so compiler will yell! \n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "#include <string>\n", "\n", @@ -242,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -261,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -273,7 +431,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -286,9 +444,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Integer hold: 5\n", + "String hold: Hello world!\n" + ] + } + ], "source": [ "#include <iostream>\n", "#include <string>\n", @@ -316,7 +483,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -338,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -350,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -370,7 +537,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -384,7 +551,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -406,7 +573,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -427,7 +594,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -439,7 +606,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -456,9 +623,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "IncrementalExecutor::executeFunction: symbol '_Z5printRK11HoldAValue3IiE' unresolved while linking [cling interface function]!\n", + "You are probably missing the definition of print(HoldAValue3<int> const&)\n", + "Maybe you need to load the corresponding shared library?\n" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "{\n", " HoldAValue3<int> hold(5);\n", @@ -475,7 +660,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -499,7 +684,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -511,7 +696,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -527,9 +712,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Underlying value is 5\n" + ] + } + ], "source": [ "{\n", " HoldAValue4<int> hold(5);\n", @@ -557,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -576,7 +769,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -590,7 +783,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -609,9 +802,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_47:3:13: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mtemplate argument for template type parameter must be a type\u001b[0m\n", + " MyArray<5ul, 5ul> array1(2); // COMPILATION ERROR!\n", + "\u001b[0;1;32m ^~~\n", + "\u001b[0m\u001b[1minput_line_44:1:16: \u001b[0m\u001b[0;1;30mnote: \u001b[0mtemplate parameter is declared here\u001b[0m\n", + "template<class TypeT, std::size_t Nelts>\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "{\n", " MyArray<5ul, 5ul> array1(2); // COMPILATION ERROR!\n", @@ -620,9 +835,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_48:3:18: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mtemplate argument for non-type template parameter must be an expression\u001b[0m\n", + " MyArray<int, int> array1(2); // COMPILATION ERROR!\n", + "\u001b[0;1;32m ^~~\n", + "\u001b[0m\u001b[1minput_line_44:1:35: \u001b[0m\u001b[0;1;30mnote: \u001b[0mtemplate parameter is declared here\u001b[0m\n", + "template<class TypeT, std::size_t Nelts>\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "{\n", " MyArray<int, int> array1(2); // COMPILATION ERROR!\n", @@ -644,7 +881,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -672,7 +909,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)_" ] @@ -682,14 +919,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, @@ -724,5 +961,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/4-Templates/2-Specialization.ipynb b/4-Templates/2-Specialization.ipynb index 477980c29b9be46f1004d06a9d9c6a43d7db1f3c..6a5f37ccfba6a29abfa3d717c4fb74eaa4559424 100644 --- a/4-Templates/2-Specialization.ipynb +++ b/4-Templates/2-Specialization.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb) - [Specialization](/notebooks/4-Templates/2-Specialization.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb) - [Specialization](./2-Specialization.ipynb)" ] }, { @@ -80,7 +80,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Please notice the syntax: the definition provides template with no parameter in the brackets, and the `T` is replaced by the specialized type. As there are no template parameters left, the definition of the specialization must be put in a compiled file (or with an [`inline` keyword](/notebooks/1-ProceduralProgramming/4-Functions.ipynb#inline-functions) in header file)\n", + "Please notice the syntax: the definition provides template with no parameter in the brackets, and the `T` is replaced by the specialized type. As there are no template parameters left, the definition of the specialization must be put in a compiled file (or with an [`inline` keyword](../1-ProceduralProgramming/4-Functions.ipynb#inline-functions) in header file)\n", "\n", "Of course, as many specialization as you wish may be provided:" ] @@ -648,7 +648,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)_" ] @@ -658,14 +658,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, @@ -700,5 +700,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/4-Templates/3-Syntax.ipynb b/4-Templates/3-Syntax.ipynb index 8b1090d109ae2034f736e783ea044145d39c10f1..daecdbda0aff13e132a434e5882baf974577fc2b 100644 --- a/4-Templates/3-Syntax.ipynb +++ b/4-Templates/3-Syntax.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb) - [Special syntax: typename, template and mandatory this](/notebooks/4-Templates/3-Syntax.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb) - [Special syntax: typename, template and mandatory this](./3-Syntax.ipynb)" ] }, { @@ -301,7 +301,7 @@ "source": [ "## Good practice: always check obvious template instantiations in test!\n", "\n", - "If you have been attentive, you might see `Print()` above is faulty: we ask to print on screen a void function... An instantiation reveals the issue:" + "If you have been very attentive, you might see `Print()` above is faulty: we ask to print on screen a void function... An instantiation reveals the issue:" ] }, { @@ -346,7 +346,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)_" ] @@ -356,14 +356,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, @@ -398,5 +398,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/4-Templates/4-Metaprogramming.ipynb b/4-Templates/4-Metaprogramming.ipynb index 2e86441d4e5d8960efe693d00a205f38175dc792..cfefa92d8783cd6149833f1b7791ae4e7c806069 100644 --- a/4-Templates/4-Metaprogramming.ipynb +++ b/4-Templates/4-Metaprogramming.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb) - [Metaprogramming](/notebooks/4-Templates/4-Metaprogramming.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb) - [Metaprogramming](./4-Metaprogramming.ipynb)" ] }, { @@ -224,7 +224,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)_" ] @@ -234,14 +234,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": false, @@ -281,5 +281,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/4-Templates/5-MoreAdvanced.ipynb b/4-Templates/5-MoreAdvanced.ipynb index 54b74cfe59dc6d6aeabbea70353226509debc82c..b0a235ceea16ff363e59332e0e31b3792870b556 100644 --- a/4-Templates/5-MoreAdvanced.ipynb +++ b/4-Templates/5-MoreAdvanced.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# [Getting started in C++](/) - [Templates](/notebooks/4-Templates/0-main.ipynb) - [Hints to more advanced concepts with templates](/notebooks/4-Templates/5-MoreAdvanced.ipynb)" + "# [Getting started in C++](/) - [Templates](./0-main.ipynb) - [Hints to more advanced concepts with templates](./5-MoreAdvanced.ipynb)" ] }, { @@ -25,7 +25,7 @@ "\n", "## Curiously recurrent template pattern (CRTP)\n", "\n", - "One of my own favourite idiom (so much I didn't resist writing an [entry](/notebooks/7-Appendix/Crtp.ipynb) about it in the appendix).\n", + "One of my own favourite idiom (so much I didn't resist writing an [entry](../7-Appendix/Crtp.ipynb) about it in the appendix).\n", "\n", "The idea behind it is to provide a same set of a given functionality to classes that have otherwise nothing in common.\n", "\n", @@ -50,7 +50,7 @@ "source": [ "## Traits\n", "\n", - "A **trait** is a member of a class which gives exclusively an information about type. For instance let's go back to the `HoldAValue` class we wrote [earlier](/notebooks/4-Templates/2-Specialization.ipynb) in our template presentation:" + "A **trait** is a member of a class which gives exclusively an information about type. For instance let's go back to the `HoldAValue` class we wrote [earlier](./2-Specialization.ipynb) in our template presentation:" ] }, { @@ -358,7 +358,7 @@ "metadata": {}, "outputs": [], "source": [ - "Print(5, \"hello\");" + "Print(5, \"hello\", \"world\");" ] }, { @@ -394,7 +394,7 @@ "\n", "You may want to be way more specific when defining a template parameter: instead of telling it might be whatever you want, you may impose that a specific template parameter should only be a type which is itself an instantiation of a template.\n", "\n", - "Let's consider a very dumb template function which purpose is to call print the value of `size()` for a STL container. We'll see them more extensively in a [dedicated notebook](/notebooks/5-UsefulConceptsAndSTL/3-Containers.ipynb), but for now you just have to know that these containers take two template parameters:\n", + "Let's consider a very dumb template function which purpose is to call print the value of `size()` for a STL container. We'll see them more extensively in a [dedicated notebook](../5-UsefulConceptsAndSTL/3-Containers.ipynb), but for now you just have to know that these containers take two template parameters:\n", "\n", "- One that describe the type inside the container (e.g. `double` for `std::vector<double>`).\n", "- Another optional one which specifies how the memory is allocated.\n", @@ -615,7 +615,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)_" ] @@ -625,14 +625,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, @@ -667,5 +667,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }