openPMD-api
 
Loading...
Searching...
No Matches
openPMD::UniquePtrWithLambda< T > Class Template Reference

Unique Pointer class that uses a dynamic destructor type. More...

#include <UniquePtr.hpp>

Inheritance diagram for openPMD::UniquePtrWithLambda< T >:

Public Types

using T_decayed = std::remove_extent_t<T>
 

Public Member Functions

 UniquePtrWithLambda (UniquePtrWithLambda &&) noexcept
 
UniquePtrWithLambdaoperator= (UniquePtrWithLambda &&) noexcept
 
 UniquePtrWithLambda (UniquePtrWithLambda const &)=delete
 
UniquePtrWithLambdaoperator= (UniquePtrWithLambda const &)=delete
 
template<typename bare_unique_ptr, typename SFINAE = std::enable_if_t< std::is_same_v<bare_unique_ptr, std::unique_ptr<T>>>>
 UniquePtrWithLambda (bare_unique_ptr)
 Conversion constructor from std::unique_ptr<T> with default deleter.
 
template<typename Del, typename SFINAE = std::enable_if_t< !std::is_same_v<std::unique_ptr<T, Del>, std::unique_ptr<T>>>>
 UniquePtrWithLambda (std::unique_ptr< T, Del >)
 Conversion constructor from std::unique_ptr<T> with custom deleter.
 
 UniquePtrWithLambda (T_decayed *)
 Construct from raw pointer with default deleter.
 
 UniquePtrWithLambda (T_decayed *, std::function< void(T_decayed *)>)
 Construct from raw pointer with custom deleter.
 
template<typename U>
UniquePtrWithLambda< U > static_cast_ () &&
 Like std::static_pointer_cast.
 

Detailed Description

template<typename T>
class openPMD::UniquePtrWithLambda< T >

Unique Pointer class that uses a dynamic destructor type.

Unlike std::shared_ptr, std::unique_ptr has a second type parameter for the destructor, in order to have as little runtime overhead as possible over raw pointers. This unique pointer class behaves like a std::unique_ptr with a std::function based deleter type, making it possible to have one single unique_ptr-like class that still enables user to specify custom destruction behavior, e.g. for GPU buffers.

If not specifying a custom deleter explicitly, this class emulates the behavior of a std::unique_ptr with std::default_delete. This also means that array types are supported as expected.

Template Parameters
TThe pointer type, as in std::unique_ptr.

Constructor & Destructor Documentation

◆ UniquePtrWithLambda() [1/2]

template<typename T>
template<typename bare_unique_ptr, typename SFINAE>
openPMD::UniquePtrWithLambda< T >::UniquePtrWithLambda ( bare_unique_ptr stdPtr)

Conversion constructor from std::unique_ptr<T> with default deleter.

Template Parameters
bare_unique_ptrEqual to std::unique_ptr<T>. Needs to be a template parameter since we cannot instantiate std::unique_ptr<void>.
SFINAEUsed to ensure that bare_unique_ptr actually is std::unique_ptr<T>.

◆ UniquePtrWithLambda() [2/2]

template<typename T>
template<typename Del, typename>
openPMD::UniquePtrWithLambda< T >::UniquePtrWithLambda ( std::unique_ptr< T, Del > ptr)

Conversion constructor from std::unique_ptr<T> with custom deleter.

Template Parameters
DelCustom deleter type.
SFINAEUsed to not compete with the std::unique_ptr<T> constructor (without custom deleter).

Member Function Documentation

◆ static_cast_()

template<typename T>
template<typename U>
UniquePtrWithLambda< U > openPMD::UniquePtrWithLambda< T >::static_cast_ ( ) &&

Like std::static_pointer_cast.

The dynamic destructor type makes this possible to implement in this case.

Template Parameters
UConvert to unique pointer of this type.

The documentation for this class was generated from the following files: