The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefits of PIMPL. This saves us from writing an enormous amount of boilerplate code for each class. More...
#include <ImplPtr.hh>
Public Member Functions | |
ImplPtr (const ImplPtr &_other) | |
Copy constructor. More... | |
ImplPtr (ImplPtr &&)=default | |
template<class U , class D , class Ops > | |
ImplPtr (U *_ptr, D &&_deleter, Ops &&_ops) | |
Constructor. More... | |
~ImplPtr ()=default | |
Destructor. More... | |
T * | Get () |
Non-const member access function. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
const T * | Get () const |
Const member access function. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
T & | operator* () |
Non-const dereference operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
const T & | operator* () const |
Const dereference operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
T * | operator-> () |
Non-const member access operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
const T * | operator-> () const |
Const member access operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More... | |
ImplPtr & | operator= (const ImplPtr &_other) |
Copy assignment operator. More... | |
ImplPtr & | operator= (ImplPtr &&)=default |
Detailed Description
template<class T, class Deleter = void (*)(T*), class Operations = detail::CopyMoveDeleteOperations<T>>
class gz::utils::ImplPtr< T, Deleter, Operations >
The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefits of PIMPL. This saves us from writing an enormous amount of boilerplate code for each class.
To follow PIMPL design principles, create an object of this type as the one and only member variable of your class, e.g.:
When constructing the dataPtr
object, pass it MakeImpl<Implementation>(/* ... args ... */)
in the initialization list of your class.
- See also
- MakeImpl<T>()
This class was inspired by the following blog post: http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html
For interface classes that should not be copiable, see the UniqueImplPtr class further down in this header.
- Note
- Switching between ImplPtr and UniqueImplPtr is NOT ABI-safe. This is essentially the same as changing whether or not the class provides a copy-constructor and a copy-assignment operator, which is bound to result in runtime linking issues at a minimum (but more importantly, it changes the binary footprint of the class). If it is not obvious whether a class should be copiable, then the safest choice is to use a UniqueImplPtr and then manually add the copy constructor/operator later if it is deemed acceptable. The next time an ABI update is permitted, those manually written functions can be removed and the UniqueImplPtr can be replaced with an ImplPtr.
Constructor & Destructor Documentation
◆ ImplPtr() [1/3]
ImplPtr | ( | U * | _ptr, |
D && | _deleter, | ||
Ops && | _ops | ||
) |
Constructor.
- Template Parameters
-
U A type that is compatible with T, i.e. either T or a class that is derived from T. D The deleter type Ops The copy operation container type
- Parameters
-
[in] _ptr The raw pointer to the implementation [in] _deleter The deleter object [in] _ops The copy operation object
◆ ImplPtr() [2/3]
Copy constructor.
- Parameters
-
[in] _other Another ImplPtr of the same type
◆ ImplPtr() [3/3]
◆ ~ImplPtr()
|
default |
Destructor.
Member Function Documentation
◆ Get() [1/2]
T* Get | ( | ) |
Non-const member access function. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- Mutable access to the contained object's members.
◆ Get() [2/2]
const T* Get | ( | ) | const |
Const member access function. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- Immutable access to the contained object's members.
◆ operator*() [1/2]
T& operator* | ( | ) |
Non-const dereference operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- A mutable reference to the contained object.
◆ operator*() [2/2]
const T& operator* | ( | ) | const |
Const dereference operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- A const-reference to the contained object.
◆ operator->() [1/2]
T* operator-> | ( | ) |
Non-const member access operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- Mutable access to the contained object's members.
◆ operator->() [2/2]
const T* operator-> | ( | ) | const |
Const member access operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.
- Returns
- Immutable access to the contained object's members.
◆ operator=() [1/2]
◆ operator=() [2/2]
The documentation for this class was generated from the following file: