8#include <userver/utils/assert.hpp>
10USERVER_NAMESPACE_BEGIN
23 constexpr CheckedPtr(std::nullptr_t)
noexcept
25 explicit constexpr CheckedPtr(T* ptr)
noexcept : ptr_{ptr} {}
27 explicit constexpr operator
bool()
const noexcept {
39 T* Get() && { RvalueDisabled(); }
41 T* operator->()
const& {
return Get(); }
42 T* operator->() && { RvalueDisabled(); }
44 T& operator*()
const& {
return *Get(); }
45 T& operator*() && { RvalueDisabled(); }
51 "Don't use temporary CheckedPtr, check it first, then dereference");
54 void CheckPointer()
const {
57 "CheckedPtr contents were not checked before dereferencing");
59 if (!ptr_)
throw std::runtime_error{
"Empty checked_pointer"};
62 mutable bool checked_{
false};
69 static_assert(!
sizeof(T),
"Don't use CheckedPointer for references");
73constexpr CheckedPtr<T> MakeCheckedPtr(T* ptr)
noexcept {