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

Enhance cetl::pmr::Factory::make_unique to support "interface/concrete" scenario. #118

Open
serges147 opened this issue Apr 22, 2024 · 0 comments

Comments

@serges147
Copy link
Contributor

  1. Currently you have to do something like this:
template <typename Tag, typename... Args>
CETL_NODISCARD UniquePtr<typename Tag::Interface> makeUniquePtr(cetl::pmr::memory_resource& memory, Args&&... args)
{
    PmrAllocator<typename Tag::Concrete> allocator{&memory};
    auto interface_deleter = typename UniquePtr<typename Tag::Interface>::deleter_type{allocator, 1};

    auto concrete  = cetl::pmr::Factory::make_unique(allocator, std::forward<Args>(args)...);
    auto interface = UniquePtr<typename Tag::Interface>{concrete.release(), interface_deleter};

    return interface;
}
  1. The above code has issue with cetl::pmr::memory_resource, namely incorrect size on deallocation (8 bytes instead of real/concrete size which was during allocate).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant