12 #ifndef DOCWIRE_NOT_NULL_H
13 #define DOCWIRE_NOT_NULL_H
15 #include "safety_policy.h"
18 #include <type_traits>
39 template <
typename Ptr, safety_policy safety_level = default_safety_level>
48 enforce<safety_level>(m_ptr !=
nullptr,
"not_null constructed with a null pointer.");
59 template <
typename... Args,
60 typename = std::enable_if_t<std::is_constructible_v<Ptr, Args...> && (
sizeof...(Args) > 1)>>
62 : m_ptr(std::forward<Args>(args)...)
64 enforce<safety_level>(m_ptr !=
nullptr,
"not_null constructed with a null pointer.");
69 not_null& operator=(std::nullptr_t) =
delete;
76 auto& operator*()
const {
return *m_ptr; }
77 auto& operator*() {
return *m_ptr; }
79 auto operator->()
const
81 return &this->operator*();
85 return &this->operator*();
88 explicit operator const Ptr&()
const {
return m_ptr; }
101 template <
typename Ptr>
A wrapper for pointer-like types that enforces a non-null invariant.
auto get() const requires requires(const Ptr &p)
Returns the raw pointer.
not_null(Ptr p, guaranteed_t)
Unchecked constructor for when the pointer is guaranteed to be non-null. This is an optimization to a...
not_null(Ptr p)
Constructs from a pointer, enforcing the non-null invariant in strict mode.
The main namespace for the DocWire SDK.
not_null< std::remove_cvref_t< Ptr > > assume_not_null(Ptr &&ptr)
Wraps a pointer-like object in a not_null, bypassing the runtime check.
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.
constexpr guaranteed_t guaranteed
A constant to use with the unchecked not_null constructor, e.g., not_null(ptr, guaranteed).
A tag to indicate that a pointer is guaranteed to be non-null, bypassing the runtime check in not_nul...