Experiments with C++17/20 pointers for ownership semantics, RAII
C++ has had issues with consistant resource ownership and smart pointers. But there are some really good ideas about how to handle this.
- CppCoreGuidelines: Resource Management
- “Writing Good C++14” by Bjarne Stroustrup
- “Writing Good C++14 … By Default” by Herb Sutter
In addition, C++17 and C++20 has since added features to make this somewhat easier.
The GSL: Guideline Support Library
provides a GSL definition of the not_null<>
class.
This seems very interesting to me, but I think there's a useful generalization to
define a default behavior for the default constructor, instead of dis-allowing it.
Explore the use of templates to define smart pointers that do not require ubiquitious validity tests like:
if (p->get() != nullptr) {
... use the pointer ...}
- unambiguous ownership of underlying resources, scoped lifetime
- thread safe
- exception safe
- portable
- efficient
- const-correct semantics
- fully unit-tested
- Investigate limited support for async-signal safe usage.