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
...@@ -516,12 +516,31 @@ ...@@ -516,12 +516,31 @@
The `const` here is important: you may access the content but should not modify it; this functionality is provided for read-only access. The `const` here is important: you may access the content but should not modify it; this functionality is provided for read-only access.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
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). 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 id: tags:
``` C++17
#include <string>
using namespace std::string_literals;
auto hello_str = "Hello world"; // declares a char*
auto hello = "Hello world"s; // declares a std::string - requires first the using namespace directive
std::string hello_string("Hello world"); // the 'classic' way to define a std::string
```
%% Cell type:markdown id: tags:
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 id: tags:
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).
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Renaming types ## Renaming types
......
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