// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include #include #include namespace Utils { namespace Internal { template class UniqueObjectInternalPointer : public QPointer { public: using QPointer::QPointer; template && !std::is_same_v, std::decay_t>>> UniqueObjectInternalPointer(const UniqueObjectInternalPointer &p) noexcept : QPointer{p.data()} {} }; template struct UniqueObjectPtrDeleter { using pointer = UniqueObjectInternalPointer; constexpr UniqueObjectPtrDeleter() noexcept = default; template>> constexpr UniqueObjectPtrDeleter(const UniqueObjectPtrDeleter &) noexcept {} constexpr void operator()(pointer p) const { static_assert(!std::is_void_v, "can't delete pointer to incomplete type"); static_assert(sizeof(Type) > 0, "can't delete pointer to incomplete type"); delete p.data(); } }; template struct UniqueObjectPtrLateDeleter { using pointer = UniqueObjectInternalPointer; constexpr UniqueObjectPtrLateDeleter() noexcept = default; template>> constexpr UniqueObjectPtrLateDeleter(const UniqueObjectPtrLateDeleter &) noexcept {} constexpr void operator()(pointer p) const { static_assert(!std::is_void_v, "can't delete pointer to incomplete type"); static_assert(sizeof(Type) > 0, "can't delete pointer to incomplete type"); p->deleteLater(); } }; } // namespace Internal template using UniqueObjectPtr = std::unique_ptr>; template auto makeUniqueObjectPtr(Arguments &&...arguments) { return UniqueObjectPtr{new Type(std::forward(arguments)...)}; } template using UniqueObjectLatePtr = std::unique_ptr>; template auto makeUniqueObjectLatePtr(Arguments &&...arguments) { return UniqueObjectLatePtr{new Type(std::forward(arguments)...)}; } } // namespace Utils