12 #ifndef DOCWIRE_REF_OR_OWNED_H
13 #define DOCWIRE_REF_OR_OWNED_H
16 #include <type_traits>
21 template<
typename U,
typename T>
22 concept ref_or_owned_compatible = std::is_convertible_v<std::shared_ptr<std::remove_reference_t<U>>, std::shared_ptr<T>>;
35 static_assert(!std::is_reference<T>::value,
"ref_or_owned<T> cannot be instantiated with a reference type");
36 static_assert(!std::is_void<T>::value,
"ref_or_owned<T> cannot be instantiated with void type");
40 : v{other.to_shared_ptr()}
44 : v{other.to_shared_ptr()}
54 template<ref_or_owned_compatible<T> U>
56 : v{std::shared_ptr<T>{&value, [](
auto*) {}}}
66 template<ref_or_owned_compatible<T> U>
68 : v{std::make_shared<std::remove_reference_t<U>>(std::forward<U>(value))}
71 template<ref_or_owned_compatible<T> U>
81 const T&
get()
const {
94 std::shared_ptr<T> to_shared_ptr()
const
100 std::shared_ptr<T> v;
A utility class that simplifies declaring function attributes that need to be stored without requirin...
ref_or_owned(U &&value)
Constructs a ref_or_owned object from a temporary object.
const T & get() const
Returns a const reference to the stored object, regardless of whether it is stored as a reference or ...
T & get()
Returns a non-const reference to the stored object, regardless of whether it is stored as a reference...
ref_or_owned(U &value)
Constructs a ref_or_owned object from a reference to an object.
The main namespace for the DocWire SDK.