mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 10:04:35 +03:00
Added example of static inline member variables to #inline varibles (#77)
* Added example of static inline member variables to #inline varibles
This commit is contained in:
12
CPP17.md
12
CPP17.md
@@ -150,6 +150,16 @@ S x2 = S{123}; // mov eax, dword ptr [.L_ZZ4mainE2x2]
|
|||||||
// .L_ZZ4mainE2x2: .long 123
|
// .L_ZZ4mainE2x2: .long 123
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It can also be used to declare and define a static member variable, such that it does not need to be initialized in the source file.
|
||||||
|
```c++
|
||||||
|
struct S {
|
||||||
|
S() : id(count++) {}
|
||||||
|
~S() {count--;}
|
||||||
|
int id;
|
||||||
|
static inline int count{0}; // declare and initialize count to 0 within the class
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### Nested namespaces
|
### Nested namespaces
|
||||||
Using the namespace resolution operator to create nested namespace definitions.
|
Using the namespace resolution operator to create nested namespace definitions.
|
||||||
```c++
|
```c++
|
||||||
@@ -393,7 +403,7 @@ The new `std::filesystem` library provides a standard way to manipulate files, d
|
|||||||
Here, a big file is copied to a temporary path if there is available space:
|
Here, a big file is copied to a temporary path if there is available space:
|
||||||
```c++
|
```c++
|
||||||
const auto bigFilePath {"bigFileToCopy"};
|
const auto bigFilePath {"bigFileToCopy"};
|
||||||
if (std::filesystem::exists(bigFilePath)) {
|
if (std::filesystem::exists(bigFilePath)) {
|
||||||
const auto bigFileSize {std::filesystem::file_size(bigFilePath)};
|
const auto bigFileSize {std::filesystem::file_size(bigFilePath)};
|
||||||
std::filesystem::path tmpPath {"/tmp"};
|
std::filesystem::path tmpPath {"/tmp"};
|
||||||
if (std::filesystem::space(tmpPath).available > bigFileSize) {
|
if (std::filesystem::space(tmpPath).available > bigFileSize) {
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -435,6 +435,16 @@ S x2 = S{123}; // mov eax, dword ptr [.L_ZZ4mainE2x2]
|
|||||||
// .L_ZZ4mainE2x2: .long 123
|
// .L_ZZ4mainE2x2: .long 123
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It can also be used to declare and define a static member variable, such that it does not need to be initialized in the source file.
|
||||||
|
```c++
|
||||||
|
struct S {
|
||||||
|
S() : id(count++) {}
|
||||||
|
~S() {count--;}
|
||||||
|
int id;
|
||||||
|
static inline int count{0}; // declare and initialize count to 0 within the class
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### Nested namespaces
|
### Nested namespaces
|
||||||
Using the namespace resolution operator to create nested namespace definitions.
|
Using the namespace resolution operator to create nested namespace definitions.
|
||||||
```c++
|
```c++
|
||||||
@@ -678,7 +688,7 @@ The new `std::filesystem` library provides a standard way to manipulate files, d
|
|||||||
Here, a big file is copied to a temporary path if there is available space:
|
Here, a big file is copied to a temporary path if there is available space:
|
||||||
```c++
|
```c++
|
||||||
const auto bigFilePath {"bigFileToCopy"};
|
const auto bigFilePath {"bigFileToCopy"};
|
||||||
if (std::filesystem::exists(bigFilePath)) {
|
if (std::filesystem::exists(bigFilePath)) {
|
||||||
const auto bigFileSize {std::filesystem::file_size(bigFilePath)};
|
const auto bigFileSize {std::filesystem::file_size(bigFilePath)};
|
||||||
std::filesystem::path tmpPath {"/tmp"};
|
std::filesystem::path tmpPath {"/tmp"};
|
||||||
if (std::filesystem::space(tmpPath).available > bigFileSize) {
|
if (std::filesystem::space(tmpPath).available > bigFileSize) {
|
||||||
@@ -1624,7 +1634,7 @@ void foo(bool clause) { /* do something... */ }
|
|||||||
|
|
||||||
std::vector<std::thread> threadsVector;
|
std::vector<std::thread> threadsVector;
|
||||||
threadsVector.emplace_back([]() {
|
threadsVector.emplace_back([]() {
|
||||||
// Lambda function that will be invoked
|
// Lambda function that will be invoked
|
||||||
});
|
});
|
||||||
threadsVector.emplace_back(foo, true); // thread will run foo(true)
|
threadsVector.emplace_back(foo, true); // thread will run foo(true)
|
||||||
for (auto& thread : threadsVector) {
|
for (auto& thread : threadsVector) {
|
||||||
|
|||||||
Reference in New Issue
Block a user