mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 10:34:35 +03:00
Cleanup; consistent formatting.
This commit is contained in:
2
CPP14.md
2
CPP14.md
@@ -181,7 +181,7 @@ decltype(auto) a2t(const std::array<T, N>& a) {
|
||||
* Prevents code repetition when specifying the underlying type the pointer shall hold.
|
||||
* Most importantly, it provides exception-safety. Suppose we were calling a function `foo` like so:
|
||||
```c++
|
||||
foo(std::unique_ptr<T>{ new T{} }, function_that_throws(), std::unique_ptr<T>{ new T{} });
|
||||
foo(std::unique_ptr<T>{new T{}}, function_that_throws(), std::unique_ptr<T>{new T{}});
|
||||
```
|
||||
The compiler is free to call `new T{}`, then `function_that_throws()`, and so on... Since we have allocated data on the heap in the first construction of a `T`, we have introduced a leak here. With `std::make_unique`, we are given exception-safety:
|
||||
```c++
|
||||
|
||||
Reference in New Issue
Block a user