userver: utils::SharedReadablePtr< T > Class Template Reference
Loading...
Searching...
No Matches
utils::SharedReadablePtr< T > Class Template Referencefinal

#include <userver/utils/shared_readable_ptr.hpp>

Detailed Description

template<typename T>
class utils::SharedReadablePtr< T >

std::shared_ptr<const T> wrapper that makes sure that the pointer is stored before dereferencing. Protects from dangling references:

// BAD! Result of `cache.Get()` may be destroyed after the invocation.
const auto& snapshot = *cache.Get();

Definition at line 22 of file shared_readable_ptr.hpp.

Public Types

using Base = std::shared_ptr<const T>
 
using MutableBase = std::shared_ptr<T>
 
using Weak = typename Base::weak_type
 
using Unique = std::unique_ptr<const T>
 
using element_type = T
 

Public Member Functions

 SharedReadablePtr (const SharedReadablePtr &ptr) noexcept=default
 
 SharedReadablePtr (SharedReadablePtr &&ptr) noexcept=default
 
constexpr SharedReadablePtr (std::nullptr_t) noexcept
 
SharedReadablePtroperator= (const SharedReadablePtr &ptr) noexcept=default
 
SharedReadablePtroperator= (SharedReadablePtr &&ptr) noexcept=default
 
 SharedReadablePtr (const Base &ptr) noexcept
 
 SharedReadablePtr (Base &&ptr) noexcept
 
 SharedReadablePtr (const MutableBase &ptr) noexcept
 
 SharedReadablePtr (MutableBase &&ptr) noexcept
 
 SharedReadablePtr (Unique &&ptr) noexcept
 
SharedReadablePtroperator= (const Base &ptr) noexcept
 
SharedReadablePtroperator= (Base &&ptr) noexcept
 
SharedReadablePtroperator= (const MutableBase &ptr) noexcept
 
SharedReadablePtroperator= (MutableBase &&ptr) noexcept
 
SharedReadablePtroperator= (std::nullptr_t) noexcept
 
const T * Get () const &noexcept
 
const T & operator* () const &noexcept
 
const T & operator* () &&
 
const T * operator-> () const &noexcept
 
const T * operator-> () &&
 
 operator const Base & () const &noexcept
 
 operator const Base & () &&
 
 operator Weak () const &noexcept
 
 operator Weak () &&
 
 operator bool () const noexcept
 
bool operator== (const SharedReadablePtr< T > &other) const
 
bool operator!= (const SharedReadablePtr< T > &other) const
 
void Reset () noexcept
 

Member Typedef Documentation

◆ Base

template<typename T >
using utils::SharedReadablePtr< T >::Base = std::shared_ptr<const T>

Definition at line 27 of file shared_readable_ptr.hpp.

◆ element_type

template<typename T >
using utils::SharedReadablePtr< T >::element_type = T

Definition at line 31 of file shared_readable_ptr.hpp.

◆ MutableBase

template<typename T >
using utils::SharedReadablePtr< T >::MutableBase = std::shared_ptr<T>

Definition at line 28 of file shared_readable_ptr.hpp.

◆ Unique

template<typename T >
using utils::SharedReadablePtr< T >::Unique = std::unique_ptr<const T>

Definition at line 30 of file shared_readable_ptr.hpp.

◆ Weak

template<typename T >
using utils::SharedReadablePtr< T >::Weak = typename Base::weak_type

Definition at line 29 of file shared_readable_ptr.hpp.

Constructor & Destructor Documentation

◆ SharedReadablePtr() [1/6]

template<typename T >
constexpr utils::SharedReadablePtr< T >::SharedReadablePtr ( std::nullptr_t )
inlineconstexprnoexcept

Definition at line 36 of file shared_readable_ptr.hpp.

◆ SharedReadablePtr() [2/6]

template<typename T >
utils::SharedReadablePtr< T >::SharedReadablePtr ( const Base & ptr)
inlinenoexcept

Definition at line 41 of file shared_readable_ptr.hpp.

◆ SharedReadablePtr() [3/6]

template<typename T >
utils::SharedReadablePtr< T >::SharedReadablePtr ( Base && ptr)
inlinenoexcept

Definition at line 43 of file shared_readable_ptr.hpp.

◆ SharedReadablePtr() [4/6]

template<typename T >
utils::SharedReadablePtr< T >::SharedReadablePtr ( const MutableBase & ptr)
inlinenoexcept

Definition at line 45 of file shared_readable_ptr.hpp.

◆ SharedReadablePtr() [5/6]

template<typename T >
utils::SharedReadablePtr< T >::SharedReadablePtr ( MutableBase && ptr)
inlinenoexcept

Definition at line 47 of file shared_readable_ptr.hpp.

◆ SharedReadablePtr() [6/6]

template<typename T >
utils::SharedReadablePtr< T >::SharedReadablePtr ( Unique && ptr)
inlinenoexcept

Definition at line 49 of file shared_readable_ptr.hpp.

Member Function Documentation

◆ Get()

template<typename T >
const T * utils::SharedReadablePtr< T >::Get ( ) const &
inlinenoexcept

Definition at line 76 of file shared_readable_ptr.hpp.

◆ operator bool()

template<typename T >
utils::SharedReadablePtr< T >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 94 of file shared_readable_ptr.hpp.

◆ operator const Base &() [1/2]

template<typename T >
utils::SharedReadablePtr< T >::operator const Base & ( ) &&
inline

Definition at line 88 of file shared_readable_ptr.hpp.

◆ operator const Base &() [2/2]

template<typename T >
utils::SharedReadablePtr< T >::operator const Base & ( ) const &
inlinenoexcept

Definition at line 86 of file shared_readable_ptr.hpp.

◆ operator Weak() [1/2]

template<typename T >
utils::SharedReadablePtr< T >::operator Weak ( ) &&
inline

Definition at line 92 of file shared_readable_ptr.hpp.

◆ operator Weak() [2/2]

template<typename T >
utils::SharedReadablePtr< T >::operator Weak ( ) const &
inlinenoexcept

Definition at line 90 of file shared_readable_ptr.hpp.

◆ operator!=()

template<typename T >
bool utils::SharedReadablePtr< T >::operator!= ( const SharedReadablePtr< T > & other) const
inline

Definition at line 98 of file shared_readable_ptr.hpp.

◆ operator*() [1/2]

template<typename T >
const T & utils::SharedReadablePtr< T >::operator* ( ) &&
inline

Definition at line 80 of file shared_readable_ptr.hpp.

◆ operator*() [2/2]

template<typename T >
const T & utils::SharedReadablePtr< T >::operator* ( ) const &
inlinenoexcept

Definition at line 78 of file shared_readable_ptr.hpp.

◆ operator->() [1/2]

template<typename T >
const T * utils::SharedReadablePtr< T >::operator-> ( ) &&
inline

Definition at line 84 of file shared_readable_ptr.hpp.

◆ operator->() [2/2]

template<typename T >
const T * utils::SharedReadablePtr< T >::operator-> ( ) const &
inlinenoexcept

Definition at line 82 of file shared_readable_ptr.hpp.

◆ operator=() [1/5]

template<typename T >
SharedReadablePtr & utils::SharedReadablePtr< T >::operator= ( Base && ptr)
inlinenoexcept

Definition at line 56 of file shared_readable_ptr.hpp.

◆ operator=() [2/5]

template<typename T >
SharedReadablePtr & utils::SharedReadablePtr< T >::operator= ( const Base & ptr)
inlinenoexcept

Definition at line 51 of file shared_readable_ptr.hpp.

◆ operator=() [3/5]

template<typename T >
SharedReadablePtr & utils::SharedReadablePtr< T >::operator= ( const MutableBase & ptr)
inlinenoexcept

Definition at line 61 of file shared_readable_ptr.hpp.

◆ operator=() [4/5]

template<typename T >
SharedReadablePtr & utils::SharedReadablePtr< T >::operator= ( MutableBase && ptr)
inlinenoexcept

Definition at line 66 of file shared_readable_ptr.hpp.

◆ operator=() [5/5]

template<typename T >
SharedReadablePtr & utils::SharedReadablePtr< T >::operator= ( std::nullptr_t )
inlinenoexcept

Definition at line 71 of file shared_readable_ptr.hpp.

◆ operator==()

template<typename T >
bool utils::SharedReadablePtr< T >::operator== ( const SharedReadablePtr< T > & other) const
inline

Definition at line 96 of file shared_readable_ptr.hpp.

◆ Reset()

template<typename T >
void utils::SharedReadablePtr< T >::Reset ( )
inlinenoexcept

Definition at line 100 of file shared_readable_ptr.hpp.


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