Dune Core Modules (2.3.1)

Dune::shared_ptr< T > Class Template Reference

A reference counting smart pointer. More...

#include <dune/common/shared_ptr.hh>

Public Types

typedef T element_type
 The data type we are a pointer for. More...
 

Public Member Functions

 shared_ptr ()
 Constructs a new smart pointer and allocates the referenced Object.
 
template<class T1 >
 shared_ptr (T1 *pointer)
 Constructs a new smart pointer from a preallocated Object. More...
 
template<class T1 , class Deleter >
 shared_ptr (T1 *pointer, Deleter deleter)
 Constructs a new smart pointer from a preallocated Object. More...
 
template<class T1 >
 shared_ptr (const shared_ptr< T1 > &pointer)
 Copy constructor. More...
 
 shared_ptr (const shared_ptr &pointer)
 Copy constructor. More...
 
 ~shared_ptr ()
 Destructor.
 
template<class T1 >
shared_ptroperator= (const shared_ptr< T1 > &pointer)
 Assignment operator.
 
shared_ptroperator= (const shared_ptr &pointer)
 Assignment operator.
 
element_typeoperator* ()
 Dereference as object.
 
element_typeoperator-> ()
 Dereference as pointer.
 
const element_typeoperator* () const
 Dereference as const object.
 
const element_typeoperator-> () const
 Dereference as const pointer.
 
element_typeget () const
 Access to the raw pointer, if you really want it.
 
 operator bool () const
 Checks if shared_ptr manages an object, i.e. whether get() != 0.
 
void swap (shared_ptr &other)
 Swap content of this shared_ptr and another.
 
void reset ()
 Decrease the reference count by one and free the memory if the reference count has reached 0.
 
template<class T1 >
void reset (T1 *pointer)
 Detach shared pointer and set it anew for the given pointer.
 
int use_count () const
 The number of shared_ptrs pointing to the object we point to.
 
 operator __unspecified_bool_type () const
 Implicit conversion to "bool".
 

Related Functions

(Note that these are not member functions.)

template<typename T >
shared_ptr< T > stackobject_to_shared_ptr (T &t)
 Convert a stack-allocated object to a shared_ptr: More...
 
template<typename T , typename T2 >
shared_ptr< T2 > stackobject_to_shared_ptr (T &t)
 Convert a stack object to a shared_ptr of a base class. More...
 

Detailed Description

template<class T>
class Dune::shared_ptr< T >

A reference counting smart pointer.

It is designed such that it is usable within a std::vector. The contained object is destroyed only if there are no more references to it.

Member Typedef Documentation

◆ element_type

template<class T >
typedef T Dune::shared_ptr< T >::element_type

The data type we are a pointer for.

This has to have a parameterless constructor.

Friends And Related Function Documentation

◆ stackobject_to_shared_ptr() [1/2]

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

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)
Convert a stack-allocated object to a shared_ptr:
Definition: shared_ptr.hh:502

◆ stackobject_to_shared_ptr() [2/2]

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

Convert a stack 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);

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 2, 22:35, 2024)