Added raw string literals to C++11 features (#96)

* Added raw string literals to C++11
This commit is contained in:
Dave
2021-04-06 00:49:02 +02:00
committed by GitHub
parent d9b99892b0
commit 17f4bc150c
2 changed files with 44 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ C++11 includes the following new language features:
- [trailing return types](#trailing-return-types)
- [noexcept specifier](#noexcept-specifier)
- [char32_t and char16_t](#char32_t-and-char16_t)
- [raw string literals](#raw-string-literals)
C++11 includes the following new library features:
- [std::move](#stdmove)
@@ -696,6 +697,27 @@ char32_t utf8_str[] = U"\u0123";
char16_t utf8_str[] = u"\u0123";
```
### Raw string literals
C++11 introduces a new way to declare string literals as "raw string literals". Characters issued from an escape sequence (tabs, line feeds, single backslashes, etc.) can be inputted raw while preserving formatting. This is useful, for example, to write literary text, which might contain a lot of quotes or special formatting. This can make your string literals easier to read and maintain.
A raw string literal is declared using the following syntax:
```
R"delimiter(raw_characters)delimiter"
```
where:
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
Example:
```cpp
// msg1 and msg2 are equivalent.
const char* msg1 = "\nHello,\n\tworld!\n";
const char* msg2 = R"(
Hello,
world!
)";
```
## C++11 Library Features
### std::move

View File

@@ -108,6 +108,7 @@ C++11 includes the following new language features:
- [trailing return types](#trailing-return-types)
- [noexcept specifier](#noexcept-specifier)
- [char32_t and char16_t](#char32_t-and-char16_t)
- [raw string literals](#raw-string-literals)
C++11 includes the following new library features:
- [std::move](#stdmove)
@@ -1932,6 +1933,27 @@ char32_t utf8_str[] = U"\u0123";
char16_t utf8_str[] = u"\u0123";
```
### Raw string literals
C++11 introduces a new way to declare string literals as "raw string literals". Characters issued from an escape sequence (tabs, line feeds, single backslashes, etc.) can be inputted raw while preserving formatting. This is useful, for example, to write literary text, which might contain a lot of quotes or special formatting. This can make your string literals easier to read and maintain.
A raw string literal is declared using the following syntax:
```
R"delimiter(raw_characters)delimiter"
```
where:
* `delimiter` is an optional sequence of characters made of any source character except parentheses, backslashes and spaces.
* `raw_characters` is any raw character sequence; must not contain the closing sequence `")delimiter"`.
Example:
```cpp
// msg1 and msg2 are equivalent.
const char* msg1 = "\nHello,\n\tworld!\n";
const char* msg2 = R"(
Hello,
world!
)";
```
## C++11 Library Features
### std::move