8#include <userver/utils/assert.hpp>
10USERVER_NAMESPACE_BEGIN
23 constexpr CheckedPtr(std::nullptr_t)
noexcept : ptr_{
nullptr} {}
24 explicit constexpr CheckedPtr(T* ptr)
noexcept : ptr_{ptr} {}
26 explicit constexpr operator
bool()
const noexcept {
38 T* Get() && { RvalueDisabled(); }
40 T* operator->()
const& {
return Get(); }
41 T* operator->() && { RvalueDisabled(); }
43 T& operator*()
const& {
return *Get(); }
44 T& operator*() && { RvalueDisabled(); }
48 static_assert(!
sizeof(T),
"Don't use temporary CheckedPtr, check it first, then dereference");
51 void CheckPointer()
const {
53 UASSERT_MSG(checked_,
"CheckedPtr contents were not checked before dereferencing");
55 if (!ptr_)
throw std::runtime_error{
"Empty checked_pointer"};
58 mutable bool checked_{
false};
65 static_assert(!
sizeof(T),
"Don't use CheckedPointer for references");
69constexpr CheckedPtr<T> MakeCheckedPtr(T* ptr)
noexcept {