diff --git a/notebooks/07_STL_Set+Map+Algorithms.ipynb b/notebooks/07_STL_Set+Map+Algorithms.ipynb index 2618e9618bbedada18c4c00d582462b30e94a19a..f13b1dd0171973cbde988ba25126650508c8a369 100644 --- a/notebooks/07_STL_Set+Map+Algorithms.ipynb +++ b/notebooks/07_STL_Set+Map+Algorithms.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "c2848a05", "metadata": {}, "outputs": [ @@ -74,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "2213e98e", "metadata": {}, "outputs": [], @@ -98,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "51fd5597", "metadata": {}, "outputs": [ @@ -107,42 +107,43 @@ "output_type": "stream", "text": [ "In file included from input_line_5:1:\n", - "In file included from /srv/conda/envs/notebook/include/xeus/xinterpreter.hpp:13:\n", - "In file included from /srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/functional:49:\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_function.h:386:20: error: invalid operands to binary expression ('const __cling_N54::myPair' and 'const __cling_N54::myPair')\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xinterpreter.hpp:13:\n", + "In file included from /home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/functional:49:\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_function.h:386:20: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1minvalid operands to binary expression ('const __cling_N53::myPair' and 'const __cling_N53::myPair')\u001b[0m\n", " { return __x < __y; }\n", - " ~~~ ^ ~~~\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_tree.h:2100:13: note: in instantiation of member function 'std::less<__cling_N54::myPair>::operator()' requested here\n", + "\u001b[0;1;32m ~~~ ^ ~~~\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_tree.h:2106:13: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::less<__cling_N53::myPair>::operator()' requested here\u001b[0m\n", " __comp = _M_impl._M_key_compare(__k, _S_key(__x));\n", - " ^\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_tree.h:2153:4: note: in instantiation of member function 'std::_Rb_tree<__cling_N54::myPair, __cling_N54::myPair, std::_Identity<__cling_N54::myPair>, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::_M_get_insert_unique_pos' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_tree.h:2159:4: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::_Rb_tree<__cling_N53::myPair, __cling_N53::myPair, std::_Identity<__cling_N53::myPair>, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::_M_get_insert_unique_pos' requested here\u001b[0m\n", " = _M_get_insert_unique_pos(_KeyOfValue()(__v));\n", - " ^\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_set.h:521:9: note: in instantiation of function template specialization 'std::_Rb_tree<__cling_N54::myPair, __cling_N54::myPair, std::_Identity<__cling_N54::myPair>, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::_M_insert_unique<__cling_N54::myPair>' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_set.h:521:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'std::_Rb_tree<__cling_N53::myPair, __cling_N53::myPair, std::_Identity<__cling_N53::myPair>, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::_M_insert_unique<__cling_N53::myPair>' requested here\u001b[0m\n", " _M_t._M_insert_unique(std::move(__x));\n", - " ^\n", - "input_line_12:2:8: note: in instantiation of member function 'std::set<__cling_N54::myPair, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::insert' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_10:2:8: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::set<__cling_N53::myPair, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::insert' requested here\u001b[0m\n", " pairs.insert( myPair(1,2) );\n", - " ^\n", - "In file included from input_line_5:1:\n", - "In file included from /srv/conda/envs/notebook/include/xeus/xinterpreter.hpp:17:\n", - "In file included from /srv/conda/envs/notebook/include/xeus/xcomm.hpp:15:\n", - "In file included from /srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/map:60:\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_tree.h:777:2: error: static_assert failed \"comparison object must be invocable with two arguments of key type\"\n", + "\u001b[0;1;32m ^\n", + "\u001b[0mIn file included from input_line_5:1:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xinterpreter.hpp:17:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xcomm.hpp:15:\n", + "In file included from /home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/map:60:\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_tree.h:774:2: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mstatic_assert failed due to requirement 'std::__is_invocable<std::less<__cling_N53::myPair> &, const __cling_N53::myPair &, const __cling_N53::myPair &>{}' \"comparison object must be invocable with two arguments of key type\"\u001b[0m\n", " static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},\n", - " ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_tree.h:2100:41: note: in instantiation of member function 'std::_Rb_tree<__cling_N54::myPair, __cling_N54::myPair, std::_Identity<__cling_N54::myPair>, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::_S_key' requested here\n", + "\u001b[0;1;32m ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_tree.h:2106:41: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::_Rb_tree<__cling_N53::myPair, __cling_N53::myPair, std::_Identity<__cling_N53::myPair>, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::_S_key' requested here\u001b[0m\n", " __comp = _M_impl._M_key_compare(__k, _S_key(__x));\n", - " ^\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_tree.h:2153:4: note: in instantiation of member function 'std::_Rb_tree<__cling_N54::myPair, __cling_N54::myPair, std::_Identity<__cling_N54::myPair>, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::_M_get_insert_unique_pos' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_tree.h:2159:4: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::_Rb_tree<__cling_N53::myPair, __cling_N53::myPair, std::_Identity<__cling_N53::myPair>, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::_M_get_insert_unique_pos' requested here\u001b[0m\n", " = _M_get_insert_unique_pos(_KeyOfValue()(__v));\n", - " ^\n", - "/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/stl_set.h:521:9: note: in instantiation of function template specialization 'std::_Rb_tree<__cling_N54::myPair, __cling_N54::myPair, std::_Identity<__cling_N54::myPair>, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::_M_insert_unique<__cling_N54::myPair>' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_set.h:521:9: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'std::_Rb_tree<__cling_N53::myPair, __cling_N53::myPair, std::_Identity<__cling_N53::myPair>, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::_M_insert_unique<__cling_N53::myPair>' requested here\u001b[0m\n", " _M_t._M_insert_unique(std::move(__x));\n", - " ^\n", - "input_line_12:2:8: note: in instantiation of member function 'std::set<__cling_N54::myPair, std::less<__cling_N54::myPair>, std::allocator<__cling_N54::myPair> >::insert' requested here\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_10:2:8: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of member function 'std::set<__cling_N53::myPair, std::less<__cling_N53::myPair>, std::allocator<__cling_N53::myPair> >::insert' requested here\u001b[0m\n", " pairs.insert( myPair(1,2) );\n", - " ^\n" + "\u001b[0;1;32m ^\n", + "\u001b[0m" ] }, { @@ -177,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "id": "e8c29594", "metadata": {}, "outputs": [ @@ -185,7 +186,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing demo.cpp\n" + "Overwriting demo.cpp\n" ] } ], @@ -240,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "id": "0a0207dd", "metadata": {}, "outputs": [], @@ -250,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "id": "68e1df4b", "metadata": {}, "outputs": [ @@ -294,7 +295,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "bdda6c33", "metadata": {}, "outputs": [ @@ -341,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "8099d1a4", "metadata": {}, "outputs": [], @@ -351,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "5d491b27", "metadata": {}, "outputs": [ @@ -397,12 +398,12 @@ "source": [ "Return to our example with the traffic light. Assume that we want to print the currect state of a specific traffic light. How to do that?\n", "\n", - "Well, using an enumeration for the state we can use the classical switch-case-construct:" + "Well, using an enumeration (class) for the state we can use the classical switch-case-construct:" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 16, "id": "59839aea", "metadata": {}, "outputs": [ @@ -410,7 +411,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing ampel.cpp\n" + "Overwriting ampel.cpp\n" ] } ], @@ -419,21 +420,21 @@ "\n", "#include <iostream>\n", "\n", - "typedef enum{ GREEN, YELLOW, RED, YELLOW_RED } trafficLight;\n", + "enum class trafficLight { GREEN, YELLOW, RED, YELLOW_RED };\n", "\n", - "void ampel( trafficLight tf ) {\n", + "void ampel( trafficLight& tf ) {\n", "\n", " switch( tf ) {\n", - " case GREEN:\n", + " case trafficLight::GREEN:\n", " std::cout << \"Lights are green\" << std::endl;\n", " break;\n", - " case YELLOW:\n", + " case trafficLight::YELLOW:\n", " std::cout << \"Lights are yellow\" << std::endl;\n", " break;\n", - " case RED:\n", + " case trafficLight::RED:\n", " std::cout << \"Lights are red\" << std::endl;\n", " break;\n", - " case YELLOW_RED:\n", + " case trafficLight::YELLOW_RED:\n", " std::cout << \"Lights are yellow-red\" << std::endl;\n", " break;\n", " }\n", @@ -441,14 +442,14 @@ "}\n", "\n", "int main() {\n", - " trafficLight tf = GREEN;\n", + " trafficLight tf = trafficLight::GREEN;\n", " ampel( tf );\n", "}" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, "id": "76c8886d", "metadata": {}, "outputs": [], @@ -458,7 +459,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 18, "id": "731e7c94", "metadata": {}, "outputs": [ @@ -484,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 23, "id": "8fe484bf", "metadata": {}, "outputs": [ @@ -502,15 +503,15 @@ "#include <iostream>\n", "#include <map>\n", "\n", - "typedef enum{ GREEN, YELLOW, RED, YELLOW_RED } trafficLight;\n", + "enum class trafficLight { GREEN, YELLOW, RED, YELLOW_RED };\n", "\n", "int main() {\n", "\n", " std::map< trafficLight, std::string > tf2str =\n", - " { { GREEN, \"green\" }, { YELLOW, \"yellow\" }, { RED, \"red\" },\n", - " { YELLOW_RED, \"yellow-red\" } };\n", + " { { trafficLight::GREEN, \"green\" }, { trafficLight::YELLOW, \"yellow\" }, { trafficLight::RED, \"red\" },\n", + " { trafficLight::YELLOW_RED, \"yellow-red\" } };\n", "\n", - " trafficLight tf = GREEN;\n", + " trafficLight tf = trafficLight::GREEN;\n", "\n", " std::cout << \"Lights are \" << tf2str[ tf ] << std::endl;\n", "}" @@ -518,7 +519,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 24, "id": "74251bd8", "metadata": {}, "outputs": [], @@ -528,7 +529,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 25, "id": "5b919ca3", "metadata": {}, "outputs": [ @@ -554,7 +555,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 7, "id": "52f631d4", "metadata": {}, "outputs": [ @@ -587,7 +588,7 @@ " // Hmmm, what happens here? No key \"k\" exists so far!\n", " std::cout << \"Value of Coulomb constant is \" << constants[ \"k\" ] << '\\n';\n", "\n", - " // find() allows to check for existance of a key; returns an iterator\n", + " // find() allows to check for existence of a key; returns an iterator\n", " // to the pair, if it is found\n", " std::cout << \"Value of pi is \" << constants.find( \"pi\" )->second << '\\n';\n", "\n", @@ -610,7 +611,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 8, "id": "aaba61ba", "metadata": {}, "outputs": [], @@ -620,7 +621,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 9, "id": "3f9362c9", "metadata": {}, "outputs": [ @@ -676,7 +677,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 10, "id": "aed454ce", "metadata": {}, "outputs": [ @@ -684,7 +685,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing uniq.cpp\n" + "Overwriting uniq.cpp\n" ] } ], @@ -699,7 +700,7 @@ "\n", "void print( const Container& box, const std::string& note ) {\n", " std::cout << \"( \";\n", - " for( int w: box ) std::cout << w << ' ';\n", + " for( const int& w: box ) std::cout << w << ' ';\n", " std::cout << \") \" << note << std::endl;\n", "}\n", " \n", @@ -716,12 +717,14 @@ "\n", " box.resize( distance( box.begin(), last ) );\n", " print( box, \" <- truncated to new length\" );\n", + "\n", + " std::cout << \"size = \" << box.size() << \"\\ncapacity = \" << box.capacity() << std::endl;\n", "}" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 11, "id": "57c92377", "metadata": {}, "outputs": [], @@ -731,7 +734,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 12, "id": "b190c1c6", "metadata": {}, "outputs": [ @@ -742,7 +745,9 @@ "( 3 5 2 4 1 2 1 ) <- unsorted\n", "( 1 1 2 2 3 4 5 ) <- sorted\n", "( 1 2 3 4 5 4 5 ) <- happened in-place\n", - "( 1 2 3 4 5 ) <- truncated to new length\n" + "( 1 2 3 4 5 ) <- truncated to new length\n", + "size = 5\n", + "capacity = 7\n" ] } ], @@ -778,7 +783,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 13, "id": "bed09ecd", "metadata": {}, "outputs": [ @@ -786,7 +791,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing accumulate.cpp\n" + "Overwriting accumulate.cpp\n" ] } ], @@ -830,7 +835,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 14, "id": "16a6d2e8", "metadata": {}, "outputs": [], @@ -840,7 +845,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 15, "id": "015eb80f", "metadata": {}, "outputs": [ @@ -870,16 +875,16 @@ ], "metadata": { "kernelspec": { - "display_name": "C++14", - "language": "C++14", - "name": "xcpp14" + "display_name": "C++17", + "language": "C++17", + "name": "xcpp17" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "14" + "version": "17" } }, "nbformat": 4, diff --git a/notebooks/08_Functors+Lambdas.ipynb b/notebooks/08_Functors+Lambdas.ipynb index 535dae021af8d6ddf90120dfba9a1f0f2755916c..95c809dae6c0de65249e55c8eb913ea1a73ae31e 100644 --- a/notebooks/08_Functors+Lambdas.ipynb +++ b/notebooks/08_Functors+Lambdas.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "96f5ab84", "metadata": {}, "outputs": [], @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "9bf146ec", "metadata": {}, "outputs": [], @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "b13aa200", "metadata": {}, "outputs": [], @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "f7a3701a", "metadata": {}, "outputs": [ @@ -132,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "8c0f30c5", "metadata": {}, "outputs": [], @@ -143,29 +143,29 @@ "\n", "public:\n", "\n", - " typedef enum { ADD, MULT } type;\n", + " enum class type { ADD, MULT };\n", "\n", " BinaryOperator() = delete;\n", - " BinaryOperator( BinaryOperator::type op ) : whatToDo( op ) {};\n", + " BinaryOperator( BinaryOperator::type op ) : whatToDo_( op ) {};\n", "\n", " int operator() ( int a, int b ) {\n", - " switch( whatToDo ) {\n", - " case ADD:\n", + " switch( whatToDo_ ) {\n", + " case type::ADD:\n", " return a+b;\n", - " case MULT:\n", + " case type::MULT:\n", " return a*b;\n", " }\n", " }\n", "\n", "private:\n", - " type whatToDo;\n", + " type whatToDo_;\n", "\n", "};" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "05517c3a-eb4b-4827-9f74-54abf0264cca", "metadata": {}, "outputs": [], @@ -175,8 +175,8 @@ " int a = 2;\n", " int b = 3;\n", "\n", - " BinaryOperator adder( BinaryOperator::ADD );\n", - " BinaryOperator multiplier( BinaryOperator::MULT );\n", + " BinaryOperator adder( BinaryOperator::type::ADD );\n", + " BinaryOperator multiplier( BinaryOperator::type::MULT );\n", "\n", " std::cout << adder( a, b ) << std::endl;\n", " std::cout << multiplier( a, b ) << std::endl;\n", @@ -185,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "2777a5a1-f8bc-4907-90e2-488967071529", "metadata": {}, "outputs": [ @@ -213,18 +213,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "856ee747", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Overwriting functor.cpp\n" - ] - } - ], + "outputs": [], "source": [ "%%file functor.cpp\n", "\n", @@ -269,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "4adb7f0b", "metadata": {}, "outputs": [], @@ -279,23 +271,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "f9bfde7f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(1,2) constructed\n", - "(3,4) constructed\n", - "p1 < p2 is true\n", - "p2 < p1 is false\n", - "(3,4) constructed\n", - "(5,6) constructed\n" - ] - } - ], + "outputs": [], "source": [ "!./a.out" ] @@ -326,7 +305,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "21120bbb-03a7-4048-97f4-0426c40c5bac", "metadata": {}, "outputs": [], @@ -337,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "bab0ab95-e5fd-4368-b3c2-77bcb869cfe0", "metadata": {}, "outputs": [], @@ -353,18 +332,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "b4e3f68a-6c70-49e7-a04c-924804c4cb35", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "empty -> nothing to do!\n" - ] - } - ], + "outputs": [], "source": [ "// std::function overloads 'operator bool' so we can check if anything is targetted, yet\n", "if( !sensible ) {\n", @@ -374,20 +345,12 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "c5b3e4d0-64b4-47c6-848f-f787bf9c0b17", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "He said captain, I said wot\n" - ] - } - ], + "outputs": [], "source": [ - "// now assign a target to our std::object\n", + "// now assign a target to our std::function object\n", "sensible = sayIt;\n", "\n", "// and perform the invocation\n", @@ -405,7 +368,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "ff8d558b-da83-46d9-9842-8e0d9d5ba56d", "metadata": {}, "outputs": [], @@ -418,21 +381,10 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "b5790b96-bf62-4d6e-ad9c-e56839882728", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "6" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "// if we want, we can alias our std::function type\n", "using binaryOp = std::function< int(int,int) >;\n", @@ -456,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "646b302f-cdf5-40ed-98f8-01d98a9b277a", "metadata": {}, "outputs": [], @@ -473,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "b56b370a-654f-4665-a86d-1b4a1497a813", "metadata": {}, "outputs": [], @@ -483,19 +435,10 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "b267e62f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Only 4 items left!\n", - "Only 3 items left!\n" - ] - } - ], + "outputs": [], "source": [ "ItemsInStore candyBox( 5 );\n", "takeOne( candyBox );\n", @@ -523,18 +466,10 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "24ad0ef1", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " 1 4 9 16 25" - ] - } - ], + "outputs": [], "source": [ "#include <vector>\n", "#include <iostream>\n", @@ -542,7 +477,7 @@ "\n", "std::vector< int > numbers{1,2,3,4,5};\n", "\n", - "for_each( numbers.begin(), numbers.end(), []( int& n ) { n *= n; } );\n", + "std::for_each( numbers.begin(), numbers.end(), []( int& n ) { n *= n; } );\n", "\n", "for( int v: numbers ) std::cout << \" \" << v;" ] @@ -591,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 7, "id": "3514f84c", "metadata": {}, "outputs": [], @@ -618,7 +553,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 8, "id": "7bca56ac", "metadata": {}, "outputs": [ @@ -658,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 9, "id": "f0fd0543", "metadata": {}, "outputs": [ @@ -668,7 +603,7 @@ "text": [ "5.0 is of type d\n", "type of a is i\n", - "What is lambda? ZN12__cling_N52216__cling_Un1Qu314EPvE3$_2\n" + "What is lambda? ZN12__cling_N51015__cling_Un1Qu35EPvE3$_1\n" ] } ], @@ -692,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 10, "id": "a32b1635", "metadata": {}, "outputs": [ @@ -700,7 +635,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting lambda.cpp\n" + "Writing lambda.cpp\n" ] } ], @@ -718,7 +653,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 11, "id": "85373b9f", "metadata": {}, "outputs": [], @@ -728,7 +663,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 12, "id": "fa038d35", "metadata": {}, "outputs": [ @@ -736,7 +671,6 @@ "name": "stdout", "output_type": "stream", "text": [ - " U _GLOBAL_OFFSET_TABLE_\n", " U __stack_chk_fail\n", "000000000000001e T test()\n", "0000000000000000 t test()::{lambda(int&)#1}::operator()(int&) const\n" @@ -766,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 19, "id": "03a872a9", "metadata": {}, "outputs": [ @@ -827,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 20, "id": "933de670", "metadata": {}, "outputs": [], @@ -837,7 +771,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 21, "id": "c485b43f", "metadata": {}, "outputs": [ @@ -869,7 +803,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 22, "id": "dcaec377", "metadata": {}, "outputs": [ @@ -877,7 +811,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting filter.cpp\n" + "Writing filter.cpp\n" ] } ], @@ -901,13 +835,13 @@ "\n", " std::cout << \"4 inRange(5,10): \" << inRange(5,10)(4) << std::endl;\n", "\n", - " auto filt = inRange(5,10);\n", + " auto filter = inRange(5,10);\n", "\n", - " std::cout << \"5 inRange(5,10): \" << filt(5) << std::endl;\n", + " std::cout << \"5 inRange(5,10): \" << filter(5) << std::endl;\n", "\n", " std::cout << std::endl;\n", "\n", - " const int NUM = 60;\n", + " const int NUM = 10000;\n", "\n", " std::random_device seed;\n", " std::mt19937 engine( seed() ); // a mersenne twister\n", @@ -939,7 +873,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 23, "id": "b45b0e4f", "metadata": {}, "outputs": [], @@ -949,7 +883,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 26, "id": "f85b1bc8", "metadata": {}, "outputs": [ @@ -961,9 +895,9 @@ "4 inRange(5,10): false\n", "5 inRange(5,10): true\n", "\n", - "7 of 60 inRange(6,6)\n", - "35 of 60 inRange(4,6)\n", - "All numbers 5 and 6: 6 6 6 5 6 6 6 5 5 5 5 6 5 5 5 5 \n", + "1715 of 10000 inRange(6,6)\n", + "5012 of 10000 inRange(4,6)\n", + "All numbers 5 and 6: 6 6 6 5 6 5 6 6 5 5 5 6 5 6 5 6 6 6 6 6 5 6 6 5 6 5 5 6 6 5 6 5 5 5 6 5 6 6 6 5 6 5 5 5 5 5 5 6 5 5 5 6 6 6 6 5 5 5 6 6 5 6 5 6 6 6 6 5 5 5 5 5 6 5 6 6 6 6 6 6 5 5 5 6 6 5 5 6 6 6 6 6 6 6 6 5 6 6 6 5 6 6 6 6 5 5 6 5 5 5 5 5 5 5 5 5 6 6 6 6 5 5 5 5 6 6 6 6 5 6 5 5 5 6 6 5 5 5 6 5 6 5 6 5 5 5 6 5 5 6 5 6 6 6 5 6 5 5 5 6 6 5 5 6 5 5 5 6 6 6 6 6 5 6 6 5 5 5 6 6 5 5 6 6 5 6 5 6 6 5 6 6 6 5 5 6 5 6 5 5 6 6 5 6 6 6 5 6 6 6 6 6 5 5 5 6 5 6 5 5 6 5 6 5 6 5 5 6 6 6 6 5 5 6 5 6 5 5 6 5 6 5 5 6 6 6 5 6 6 5 5 5 5 6 6 5 5 6 6 5 6 5 6 5 6 6 5 5 5 5 6 6 6 6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 33, + "execution_count": 27, "id": "cf33e115", "metadata": {}, "outputs": [ @@ -995,7 +929,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Overwriting convert.cpp\n" + "Writing convert.cpp\n" ] } ], @@ -1031,14 +965,14 @@ " << std::endl;\n", "\n", " std::cout << \"Type of expl2 is instance of std::function? \" \n", - " << std::is_same< sType, decltype( expl2 ) >::value\n", + " << std::is_same_v< sType, decltype( expl2 ) >\n", " << std::endl;\n", "}" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 28, "id": "3fbad575", "metadata": {}, "outputs": [], @@ -1048,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 29, "id": "0584e221", "metadata": {}, "outputs": [ @@ -1081,7 +1015,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 30, "id": "ae57e2ba", "metadata": {}, "outputs": [ @@ -1091,7 +1025,7 @@ "10.000000" ] }, - "execution_count": 36, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -1113,7 +1047,7 @@ "real_t m = real_c(5);\n", "\n", "std::function< real_t(const Point3D&) > solFunc =\n", - " [k, m](const Point3D& x) { return sin( k * pi * x[0] ) * sin( m * pi * x[1]; };\n", + " [k, m](const Point3D& x) { return std::sin( k * pi * x[0] ) * std::sin( m * pi * x[1]; };\n", "\n", "P1Function< real_t > uExact( \"u_analytic\", storage, maxLevel, maxLevel );\n", "uExact.interpolate( solFunc, maxLevel );\n", diff --git a/notebooks/09_Inheritance.ipynb b/notebooks/09_Inheritance.ipynb index 3bc2dcf8e921b11fc490306b3b22f9c95ed449d6..43762fe92ea4e8d84b0e63da6b8f0f3aee8e25dc 100644 --- a/notebooks/09_Inheritance.ipynb +++ b/notebooks/09_Inheritance.ipynb @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "id": "686fb768", "metadata": {}, "outputs": [], @@ -92,17 +92,17 @@ "\n", "public:\n", " person() = default;\n", - " person( const std::string& name ) : name(name) {};\n", + " person( const std::string& name ) : name_(name) {};\n", "\n", - " void set_name( const std::string& n ) { name = n; }\n", - " std::string get_name() const { return name; }\n", + " void set_name( const std::string& n ) { name_ = n; }\n", + " const std::string& get_name() const { return name_; }\n", "\n", " void all_info() const {\n", - " std::cout << \"[person] My name is \" << name << std::endl;\n", + " std::cout << \"[person] My name is \" << name_ << std::endl;\n", " }\n", "\n", "private:\n", - " std::string name;\n", + " std::string name_;\n", "};" ] }, @@ -120,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "id": "9c807fff", "metadata": {}, "outputs": [], @@ -128,16 +128,16 @@ "class student : public person {\n", "\n", "public:\n", - " student( const std::string& name, const std::string program ) :\n", - " person(name), program(program) {}\n", + " student( const std::string& name, const std::string& program ) :\n", + " person(name), program_(program) {}\n", "\n", " void all_info() const {\n", " std::cout << \"[student] My name is \" << get_name()\n", - " << \", I study \" << program << std::endl;\n", + " << \", I study \" << program_ << std::endl;\n", " }\n", "\n", "private:\n", - " std::string program;\n", + " std::string program_;\n", "};" ] }, @@ -156,7 +156,7 @@ "id": "6c7ce817", "metadata": {}, "source": [ - "Answer to the question is that `student` has no access to `person::name` because the latter is marked `private`. However, it inherits `name`, that's also why the constructor delegation worked.\n", + "Answer to the question is that `student` has no access to `person::name_` because the latter is marked `private`. However, it inherits `name_`, that's also why the constructor delegation worked.\n", "\n", "**Note:** A child inherits **all** methods and attributes from its parent, but does not necessarily have access to these." ] @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "id": "bd768c68", "metadata": {}, "outputs": [], @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "id": "780348e2", "metadata": {}, "outputs": [ @@ -253,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "fd4597ea", "metadata": {}, "outputs": [], @@ -301,22 +301,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "5c2921f9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[person] My name is Jane Doe\n", - "[student] My name is Joe Smith, I study Geophysics\n", - "[person] My name is Joe Smith\n", - "[person] My name is Joe Smith\n", - "[person] My name is Joe Smith\n" - ] - } - ], + "outputs": [], "source": [ "main();" ] @@ -335,11 +323,12 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "4d0cddfe", "metadata": {}, "outputs": [], "source": [ + "#include <iostream>\n", "struct A {\n", " A( int iVal ) : value(iVal) {};\n", " int value;\n", @@ -356,19 +345,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "9e8483cd", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "A::value = 2\n", - "B::value = 3.5\n" - ] - } - ], + "outputs": [], "source": [ "int main() {\n", " B obj( 2, 3.5 );\n", @@ -387,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "a1919205", "metadata": {}, "outputs": [], @@ -408,19 +388,10 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "742d12ee", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Child::func() was called with argument '7'\n", - "Parent::func() was called!\n" - ] - } - ], + "outputs": [], "source": [ "Child son;\n", "\n", @@ -441,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "7976790d", "metadata": {}, "outputs": [], @@ -462,19 +433,10 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "869bae76", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Child::func() was called with argument '2'\n", - "Parent::func() was called!\n" - ] - } - ], + "outputs": [], "source": [ "AnotherChild daughter;\n", "\n", @@ -493,40 +455,10 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "d1ea8b46", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[1minput_line_28:3:13: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno matching constructor for initialization of '__cling_N522::researcher'\u001b[0m\n", - " researcher smart( \"Smartie Clever\");\n", - "\u001b[0;1;32m ^ ~~~~~~~~~~~~~~~~\n", - "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit copy constructor) not viable: no known\n", - " conversion from 'const char [15]' to 'const __cling_N522::researcher' for\n", - " 1st argument\u001b[0m\n", - "class researcher : public person {};\n", - "\u001b[0;1;32m ^\n", - "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit move constructor) not viable: no known\n", - " conversion from 'const char [15]' to '__cling_N522::researcher' for 1st\n", - " argument\u001b[0m\n", - "class researcher : public person {};\n", - "\u001b[0;1;32m ^\n", - "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit default constructor) not viable: requires 0\n", - " arguments, but 1 was provided\u001b[0m\n" - ] - }, - { - "ename": "Interpreter Error", - "evalue": "", - "output_type": "error", - "traceback": [ - "Interpreter Error: " - ] - } - ], + "outputs": [], "source": [ "class researcher : public person {};\n", "researcher smart( \"Smartie Clever\");" @@ -542,19 +474,12 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "481fc3f5", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Smartie Clever\n" - ] - } - ], + "outputs": [], "source": [ + "#include <iostream>\n", "class researcher : public person {\n", " using person::person;\n", "};\n", @@ -572,18 +497,10 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "ed941226", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello Smartie Clever\n" - ] - } - ], + "outputs": [], "source": [ "class researcher : public person {\n", "public:\n", @@ -609,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "id": "1493af7c", "metadata": {}, "outputs": [], @@ -635,59 +552,30 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "id": "7802babb", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "GrandParent's c'tor invoked\n", - "Parent's c'tor invoked\n" - ] - } - ], + "outputs": [], "source": [ "Parent walton;" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "id": "57215968", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "GrandParent's c'tor invoked\n", - "Parent's c'tor invoked\n", - "Child's c'tor invoked\n" - ] - } - ], + "outputs": [], "source": [ "auto jim_bob = new Child;" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "be7a63fe", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Child's d'tor invoked\n", - "Parent's d'tor invoked\n", - "GrandParent's d'tor invoked\n" - ] - } - ], + "outputs": [], "source": [ "delete jim_bob;" ]