#include <userver/utils/shared_readable_ptr.hpp>
std::shared_ptr<const T>
wrapper that makes sure that the pointer is stored before dereferencing. Protects from dangling references.
Example of dangling:
Such code is may work fine 99.9% of that time and, and such bugs are not detectable by most tests. This is because typically the cache data will be held by the cache itself longer than the runtime of the current handler (or whatever) that uses the data. However, 0.1% of the time there will be a crash, because at that exact time the cache will update itself, replacing the data snapshot and dropping the old shared pointer, which will turn out to be the only one.
The correct way to handle shared pointers:
Definition at line 39 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 |
SharedReadablePtr & | operator= (const SharedReadablePtr &ptr) noexcept=default |
SharedReadablePtr & | operator= (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 | |
SharedReadablePtr & | operator= (const Base &ptr) noexcept |
SharedReadablePtr & | operator= (Base &&ptr) noexcept |
SharedReadablePtr & | operator= (const MutableBase &ptr) noexcept |
SharedReadablePtr & | operator= (MutableBase &&ptr) noexcept |
SharedReadablePtr & | operator= (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 |
using utils::SharedReadablePtr< T >::Base = std::shared_ptr<const T> |
Definition at line 44 of file shared_readable_ptr.hpp.
using utils::SharedReadablePtr< T >::element_type = T |
Definition at line 48 of file shared_readable_ptr.hpp.
using utils::SharedReadablePtr< T >::MutableBase = std::shared_ptr<T> |
Definition at line 45 of file shared_readable_ptr.hpp.
using utils::SharedReadablePtr< T >::Unique = std::unique_ptr<const T> |
Definition at line 47 of file shared_readable_ptr.hpp.
using utils::SharedReadablePtr< T >::Weak = typename Base::weak_type |
Definition at line 46 of file shared_readable_ptr.hpp.
|
inlineconstexprnoexcept |
Definition at line 53 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 58 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 60 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 62 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 64 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 66 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 93 of file shared_readable_ptr.hpp.
|
inlineexplicitnoexcept |
Definition at line 111 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 105 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 103 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 109 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 107 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 115 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 97 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 95 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 101 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 99 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 73 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 68 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 78 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 83 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 88 of file shared_readable_ptr.hpp.
|
inline |
Definition at line 113 of file shared_readable_ptr.hpp.
|
inlinenoexcept |
Definition at line 117 of file shared_readable_ptr.hpp.