Dune Core Modules (2.6.0)

Dune::null_deleter< T > Struct Template Reference

implements the Deleter concept of shared_ptr without deleting anything More...

#include <dune/common/shared_ptr.hh>

Related Functions

(Note that these are not member functions.)

template<typename T >
shared_ptr< T > stackobject_to_shared_ptr (T &t)
 Create a shared_ptr for a stack-allocated object. More...
 
template<typename T , typename T2 >
std::enable_if_t< not std::is_same< T, T2 >::value, shared_ptr< T > > stackobject_to_shared_ptr (T2 &t)
 Create a shared_ptr to a base class for a stack-allocated object. More...
 

Detailed Description

template<class T>
struct Dune::null_deleter< T >

implements the Deleter concept of shared_ptr without deleting anything

If you allocate an object on the stack, but want to pass it to a class or function as a shared_ptr, you can use this deleter to avoid accidental deletion of the stack-allocated object.

For convenience we provide two free functions to create a shared_ptr from a stack-allocated object (

See also
stackobject_to_shared_ptr):

1) Convert a stack-allocated object to a shared_ptr:

int i = 10;
shared_ptr<int> pi = stackobject_to_shared_ptr(i);
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75

2) Convert a stack-allocated object to a shared_ptr of a base class

class A {};
class B : public A {};
...
B b;
shared_ptr<A> pa = stackobject_to_shared_ptr<A>(b);
Template Parameters
Ttype of the stack-allocated object

Friends And Related Function Documentation

◆ stackobject_to_shared_ptr() [1/2]

template<typename T >
shared_ptr< T > stackobject_to_shared_ptr ( T &  t)
related

Create a shared_ptr for a stack-allocated object.

This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...

Usage:

int i = 10;
shared_ptr<int> pi = stackobject_to_shared_ptr(i);

The shared_ptr points to the object on the stack, but its deleter is set to an instance of null_deleter so that nothing happens when the shared_ptr is destroyed.

See also
shared_ptr, null_deleter

◆ stackobject_to_shared_ptr() [2/2]

template<typename T , typename T2 >
std::enable_if_t< not std::is_same< T, T2 >::value, shared_ptr< T > > stackobject_to_shared_ptr ( T2 &  t)
related

Create a shared_ptr to a base class for a stack-allocated object.

Usage:

class A {};
class B : public A {};
...
B b;
shared_ptr<A> pa = stackobject_to_shared_ptr<A>(b);

The shared_ptr points to the object on the stack, but its deleter is set to an instance of null_deleter so that nothing happens when the shared_ptr is destroyed.

See also
shared_ptr, null_deleter
Deprecated:
"Do not use the explicit casting version of stackobject_to_shared_ptr, just assign the result to a shared_ptr to the base class"

The documentation for this struct was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)