Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DarkPointer factory method for unique_ptr #52

Open
thirtytwobits opened this issue Jul 21, 2023 · 0 comments
Open

Add DarkPointer factory method for unique_ptr #52

thirtytwobits opened this issue Jul 21, 2023 · 0 comments
Labels
under consideration New feature or request

Comments

@thirtytwobits
Copy link
Member

    template <typename T>
    using allocator_t = cetl::pmr::polymorphic_allocator<T>;

    template <typename T>
    using dark_ptr_t = std::unique_ptr<T, cetl::pmr::PolymorphicDeleter<allocator_t<T>>>;

    /// Construct a new concrete type but return a unique_ptr to an interface type for the concrete object.
    /// Because the concrete type is no longer visible, except by using RTTI or IPolymorphicType, after the
    /// pointer is constructed it is referred to as a "Dark" pointer.
    template <typename InterfaceType, typename ConcreteType, typename... Args>
    static dark_ptr_t<InterfaceType> make_unique(allocator_t<ConcreteType> concrete_allocator, Args&&... args)
    {
...

One of the dangers of the dark pointer is, if a user calls release the object returned cannot be safely deleted unless the caller also gets the deleter. It might be worth encapsulating std::unique_ptr to account for this danger?

@thirtytwobits thirtytwobits added the under consideration New feature or request label Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under consideration New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant