BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslma::ManagedPtrUtil Struct Reference

#include <bslma_managedptr.h>

Detailed Description

This utility class provides a general no-op deleter, which is useful when creating managed pointers to stack-allocated objects.

See bslma_managedptr

Static Public Member Functions

static void noOpDeleter (void *, void *)
 
template<class ELEMENT_TYPE >
static void allocatorDeleter (void *object, void *allocator)
 
template<class ELEMENT_TYPE , class... ARGS>
static ManagedPtr< ELEMENT_TYPE > allocateManaged (bslma::Allocator *allocator, ARGS &&... args)
 
template<class ELEMENT_TYPE , class ALLOCATOR , class... ARGS>
static bsl::enable_if< bsl::is_class< ALLOCATOR >::value, ManagedPtr< ELEMENT_TYPE > >::type allocateManaged (const ALLOCATOR &allocator, ARGS &&... args)
 
template<class ELEMENT_TYPE , class... ARGS>
static ManagedPtr< ELEMENT_TYPE > makeManaged (ARGS &&... args)
 

Member Function Documentation

◆ allocateManaged() [1/2]

template<class ELEMENT_TYPE , class... ARGS>
ManagedPtr< ELEMENT_TYPE > bslma::ManagedPtrUtil::allocateManaged ( bslma::Allocator allocator,
ARGS &&...  args 
)
inlinestatic

Create an object of the (template parameter) ELEMENT_TYPE from the specified args... arguments, and return a ManagedPtr to manage the new object. Use the specified allocator to supply memory for the footprint of the new object and implicitly pass allocator as the allocator argument to the ELEMENT_TYPE constructor if bslma::UsesBslmaAllocator<ELEMENT_TYPE>::value is true. If allocator is a null pointer, the currently installed default allocator is used.

Note
Note that compilation will fail unless allocator is convertible to either bslma::Allocator * or bsl::allocator<>.

◆ allocateManaged() [2/2]

template<class ELEMENT_TYPE , class ALLOCATOR , class... ARGS>
bsl::enable_if< bsl::is_class< ALLOCATOR >::value, ManagedPtr< ELEMENT_TYPE > >::type bslma::ManagedPtrUtil::allocateManaged ( const ALLOCATOR &  allocator,
ARGS &&...  args 
)
inlinestatic

◆ allocatorDeleter()

template<class ELEMENT_TYPE >
void bslma::ManagedPtrUtil::allocatorDeleter ( void *  object,
void *  allocator 
)
inlinestatic

Make use of AllocatorUtil::deleteObject to destroy and deallocate the specified object using the specified allocator.

Precondition
The behavior is undefined unless allocator is an instance of bslma::Allocator that was used to supply memory for object and object points to an instance of ELEMENT_TYPE that is within its lifetime.

◆ makeManaged()

template<class ELEMENT_TYPE , class... ARGS>
ManagedPtr< ELEMENT_TYPE > bslma::ManagedPtrUtil::makeManaged ( ARGS &&...  args)
inlinestatic

Create an object of the (template parameter) ELEMENT_TYPE from the specified args... arguments, and return a ManagedPtr to manage the new object. Use the currently installed default allocator to supply memory for the footprint of the new object but do not implicitly pass the default allocator as the allocator argument to its constructor even if bslma::UsesBslmaAllocator<ELEMENT_TYPE>::value is true.

Note
Note that an allocator may be included in args, but see allocateManaged for an alternative function that is better suited to creating managed pointers to objects of allocator-aware type.

◆ noOpDeleter()

static void bslma::ManagedPtrUtil::noOpDeleter ( void *  ,
void *   
)
static

Deleter function that does nothing.


The documentation for this struct was generated from the following file: