Dune Core Modules (2.7.1)

Dune::ToUniquePtr< T > Class Template Reference

An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied. Transfers ownership by cast to any (smart) pointer type. Releases the stored pointer on transfer. NOTE: This is an intermediate solution to switch to std::unique_ptr in later releases smoothly. More...

#include <dune/common/to_unique_ptr.hh>

Public Member Functions

 ToUniquePtr (pointer ptr=pointer()) noexcept
 Constructor, stores the pointer.
 
 ToUniquePtr (std::nullptr_t) noexcept
 Constructor, creates a nullptr
 
 operator pointer () noexcept
 Convert to underlying pointer, releases the stored pointer. NOTE: deprecated. More...
 
 operator std::unique_ptr< T > () noexcept
 Convert to unique_ptr, invalidates the stored pointer.
 
 operator std::shared_ptr< T > () noexcept
 Convert to shared_ptr, invalidates the stored pointer.
 
 operator bool () noexcept
 Checks whether *this owns an object.
 
 operator bool () const noexcept
 Checks whether *this owns an object.
 
T * operator-> ()
 STL member.
 

Public Attributes

ptr
 STL member.
 

Related Functions

(Note that these are not member functions.)

template<class T , class... Args>
ToUniquePtr< T > makeToUnique (Args &&... args)
 Constructs an object of type T and wraps it in a ToUniquePtr,.
 

Detailed Description

template<class T>
class Dune::ToUniquePtr< T >

An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied. Transfers ownership by cast to any (smart) pointer type. Releases the stored pointer on transfer. NOTE: This is an intermediate solution to switch to std::unique_ptr in later releases smoothly.

Example of usage:

ToUniquePtr<int> f() { return new int(1); }
auto g() { return makeToUnique<int>(2); }
int* p1 = f(); // p1 gets ownership, must delete explicitly
delete p1;
std::unique_ptr<int> p2 = f();
std::shared_ptr<int> p3 = f();
auto p4 = f(); // ToUniquePtr has itself pointer semantic
std::cout << *p4 << '\n';
std::unique_ptr<int> p5( g() );
An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied....
Definition: to_unique_ptr.hh:37

Member Function Documentation

◆ operator pointer()

template<class T >
Dune::ToUniquePtr< T >::operator pointer ( )
inlinenoexcept

Convert to underlying pointer, releases the stored pointer. NOTE: deprecated.

Deprecated:
"Cast to raw pointer is deprecated. Use std::unique_ptr or std::shared_ptr instead."

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.111.3 (Nov 12, 23:30, 2024)