9#include <userver/utils/assert.hpp>
11USERVER_NAMESPACE_BEGIN
24 constexpr CheckedPtr(std::nullptr_t)
noexcept : ptr_{
nullptr} {}
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(); }
49 static_assert(!
sizeof(T),
"Don't use temporary CheckedPtr, check it first, then dereference");
52 void CheckPointer()
const {
54 UASSERT_MSG(checked_,
"CheckedPtr contents were not checked before dereferencing");
56 if (!ptr_)
throw std::runtime_error{
"Empty checked_pointer"};
59 mutable bool checked_{
false};
66 static_assert(!
sizeof(T),
"Don't use CheckedPointer for references");
70constexpr CheckedPtr<T> MakeCheckedPtr(T* ptr)
noexcept {