25#ifndef TGUI_COPIED_PTR_HPP
26#define TGUI_COPIED_PTR_HPP
30#include <TGUI/Config.hpp>
42 struct CopiedPtrEmplaceTag
44 explicit CopiedPtrEmplaceTag() =
default;
74 template <
typename... Args>
76 m_ptr(std::make_unique<T>(args...)),
77 m_cloner([](const void* val) -> void* {
return new T(*
static_cast<const T*
>(val)); })
85 m_ptr(other.m_ptr ? static_cast<T*>(other.m_cloner(other.m_ptr.
get())) : nullptr),
86 m_cloner(other.m_cloner)
95 m_ptr(other.m_ptr ? static_cast<T*>(other.m_cloner(other.m_ptr.
get())) : nullptr),
96 m_cloner(other.m_cloner)
104 m_ptr(std::move(other.m_ptr)),
105 m_cloner(std::move(other.m_cloner))
112 template <
typename U>
114 m_ptr(std::move(other.m_ptr)),
115 m_cloner(std::move(other.m_cloner))
122 void swap(CopiedPtr& other)
noexcept
124 std::swap(m_ptr, other.m_ptr);
125 std::swap(m_cloner, other.m_cloner);
141 template <
typename U>
161 template <
typename U>
187 operator bool()
const
189 return m_ptr !=
nullptr;
195 [[nodiscard]] T*
get()
const
210 std::unique_ptr<T> m_ptr;
213 void* (*m_cloner)(
const void*) =
nullptr;
216 template <
typename U>
223 template <
typename T,
typename... Args>
Copyable smart pointer template.
Definition CopiedPtr.hpp:55
CopiedPtr & operator=(const CopiedPtr< U > &other)
Copy assignment operator for a pointer to a derived object.
Definition CopiedPtr.hpp:142
CopiedPtr & operator=(CopiedPtr< U > &&other)
Move assignment operator for a pointer to a derived object.
Definition CopiedPtr.hpp:162
CopiedPtr()=default
Default constructor that initializes the object to a nullptr.
CopiedPtr(CopiedPtr &&other) noexcept
Move constructor.
Definition CopiedPtr.hpp:103
void swap(CopiedPtr &other) noexcept
Exchanges the values of *this and other.
Definition CopiedPtr.hpp:122
T * operator->() const
Dereferences the pointer for member access.
Definition CopiedPtr.hpp:179
CopiedPtr & operator=(CopiedPtr &&other) noexcept
Move assignment operator.
Definition CopiedPtr.hpp:151
CopiedPtr(CopiedPtr &&other)
Move constructor that takes a pointer to a derived object.
Definition CopiedPtr.hpp:113
CopiedPtr(std::nullptr_t)
Constructor that accepts a nullptr as parameter.
Definition CopiedPtr.hpp:65
CopiedPtr(const CopiedPtr< U > &other)
Copy constructor that takes a pointer to a derived object.
Definition CopiedPtr.hpp:94
CopiedPtr & operator=(const CopiedPtr &other)
Copy assignment operator.
Definition CopiedPtr.hpp:131
void reset()
Reset the pointer to a nullptr.
Definition CopiedPtr.hpp:203
CopiedPtr(CopiedPtrEmplaceTag, Args &&... args)
Constructor that creates a new object.
Definition CopiedPtr.hpp:75
CopiedPtr(const CopiedPtr &other)
Copy constructor.
Definition CopiedPtr.hpp:84
T & operator*()
Dereferences the pointer.
Definition CopiedPtr.hpp:171
T * get() const
Returns a raw pointer to the underlying object.
Definition CopiedPtr.hpp:195
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
CopiedPtr< T > makeCopied(Args &&... args)
Creates a CopiedPtr object that contains a value.
Definition CopiedPtr.hpp:224
Definition CopiedPtr.hpp:43