Navigation
API > API/Runtime > API/Runtime/Core
Single-ownership smart pointer similar to TUniquePtr but with a few differences which make it particularly useful for (but not limited to) implementing the pimpl pattern:
https://en.cppreference.com/w/cpp/language/pimpl
Some of the features:
Like TUniquePtr:
- Unique ownership - no reference counting.
- Move-only, no copying by default.
- Has the same static footprint as a pointer.
Like TSharedPtr:
- The deleter is determined at binding time and type-erased, allowing the object to be deleted without access to the definition of the type.
- Has additional heap footprint (but smaller than TSharedPtr).
Unlike both:
- No custom deleter support.
- No derived->base pointer conversion support (impossible to implement in C++ in a good way with multiple inheritance, and not typically needed for pimpls).
- The pointed-to object must be created with its Make function - it cannot take ownership of an existing pointer.
- No array support.
The main benefits of this class which make it useful for pimpls:
- Has single-ownership semantics.
- Has the same performance and footprint as a pointer to the object, and minimal overhead on construction and destruction.
- Can be added as a class member with a forward-declared type without having to worry about the proper definition of constructors and other special member functions.
- Can support deep copying, including with forward declared types Specifies the copy mode for TPimplPtr
| Name | EPimplPtrMode |
| Type | enum |
| Header File | /Engine/Source/Runtime/Core/Public/Templates/PimplPtr.h |
| Include Path | #include "Templates/PimplPtr.h" |
Syntax
enum EPimplPtrMode
{
NoCopy,
DeepCopy,
}
Values
| Name | Remarks |
|---|---|
| NoCopy | Don't support copying (default) |
| DeepCopy | Support deep copying, including of forward declared types |