26#ifndef RESOURCEHOLDER_H
27#define RESOURCEHOLDER_H
31template<
typename T>
requires requires(
T* copyable) { copyable->get_copy(); }
33 std::unique_ptr<T>
object =
nullptr;
39 : object(std::forward<std::unique_ptr<
T>>(obj)) {}
42 object = original_object->get_copy();
47 object = std::forward<std::unique_ptr<T>>(original_object);
52 : object(old_holder.object ? old_holder.object->get_copy() : nullptr) {}
60 T* operator->()
const {
return object.get(); }
62 explicit operator bool()
const {
return object !=
nullptr; }
66 bool operator==(
const T& other)
const {
return object == other; }
68 bool operator==(std::nullptr_t null)
const {
return object == null; }
Definition: ResourceHolder.h:32
ResourceHolder & operator=(ResourceHolder &&) noexcept=delete
ResourceHolder(std::unique_ptr< T > &&obj)
Definition: ResourceHolder.h:38
ResourceHolder(const ResourceHolder &old_holder)
Definition: ResourceHolder.h:51
ResourceHolder & operator=(const std::shared_ptr< T > &original_object)
Definition: ResourceHolder.h:41
bool operator==(const T &other) const
Definition: ResourceHolder.h:66
bool operator==(std::nullptr_t null) const
Definition: ResourceHolder.h:68
ResourceHolder(ResourceHolder &&old_holder) noexcept
Definition: ResourceHolder.h:54
bool operator==(const ResourceHolder &other) const
Definition: ResourceHolder.h:64
ResourceHolder & operator=(std::unique_ptr< T > &&original_object)
Definition: ResourceHolder.h:46
ResourceHolder & operator=(const ResourceHolder &)=delete