Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Changes
Page history
Update cpp
authored
Aug 13, 2023
by
umaumax
Show whitespace changes
Inline
Side-by-side
cpp.md
View page @
b0e12a33
...
...
@@ -620,6 +620,16 @@ if (std::regex_match(std::string("str[i]"), match, re)) {}
### std::shared_ptrでラップしても、基底クラスに継承クラスを代入可能である
### コピー代入ではなくstd::moveを利用するとパフォーマンスが改善できる
[
shared_ptr - cpprefjp C++日本語リファレンス
](
https://cpprefjp.github.io/reference/memory/shared_ptr.html
)
> 非スレッドセーフに参照カウントを増減させる方法はない。シングルスレッドでのパフォーマンスが重要で、スレッドセーフであることによるオーバーヘッドが問題になる場合、ムーブを活用すればパフォーマンスを改善できる。
```
diff
- piyo = hoge_shared_ptr;
+ piyo = std::move(hoge_shared_ptr);
```
### ラムダ関数との組み合わせの注意点
[
cpp\-examples/pitfalls/shared\_ptr at master · umaumax/cpp\-examples
](
https://github.com/umaumax/cpp-examples/tree/master/pitfalls/shared_ptr
)
...
...
...
...