Commit 33b66aed authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

Types notebook: add the possibility to declare std::string from string...

Types notebook: add the possibility to declare std::string from string litterals with 's' suffix (I learned that while preparing string view notebooks).
parent 388bebbb
......@@ -690,7 +690,36 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Please notice C++17 introduced [std::string_view](https://en.cppreference.com/w/cpp/header/string_view) which is more efficient than `std::string` for some operations (it is presented [in appendix](../7-Appendix/StringView.ipynb) but if it's your first reading it's a bit early to tackle it now).\n"
"FYI, C++ 14 introduced a suffix to facilitate declaration of a `std::string` from a string litterals... but which requires to add a specific `using namespace` first (we will see that those are in a [much later notebook](../6-InRealEnvironment/5-Namespace.ipynb)). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <string>\n",
"\n",
"using namespace std::string_literals;\n",
"\n",
"auto hello_str = \"Hello world\"; // declares a char*\n",
"auto hello = \"Hello world\"s; // declares a std::string - requires first the using namespace directive\n",
"std::string hello_string(\"Hello world\"); // the 'classic' way to define a std::string"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Not sure it it is entirely worth it (maybe when you define loads of `std::string` is a same file?) but you may see that in an existing program."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"FYI as well, C++17 introduced [std::string_view](https://en.cppreference.com/w/cpp/header/string_view) which is more efficient than `std::string` for some operations (it is presented [in appendix](../7-Appendix/StringView.ipynb) but if it's your first reading it's a bit early to tackle it now)."
]
},
{
......
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