Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A Smart pointer with custom deleter with 'using pointer = '

To manage libmagic's magic_t aka magic_set* cookie with a unique_ptr and a custom deleter in a RAII wrapper, I have: struct MagicDeleter { // magic_t is already a pointer (magic_set*) ...

1 answer  ·  posted 12d ago by dode‭  ·  last activity 12d ago by Indi‭

Question c++ resources smart-pointers
#1: Initial revision by user avatar dode‭ · 2026-09-05T09:52:10Z (12 days ago)
Smart pointer with custom deleter with 'using pointer = <pointer type>'
To manage libmagic's `magic_t` aka `magic_set*` cookie with a `unique_ptr` and a custom deleter in a RAII wrapper, I have:

    struct MagicDeleter {

        // magic_t is already a pointer (magic_set*)
        using pointer = magic_t;

        void operator()(magic_t cookie) noexcept {
            if (cookie) magic_close(cookie);
        }
    };

    using unique_magic_ptr = std::unique_ptr<magic_t, MagicDeleter>;

and then initialize and use it like:

    m_cookie {unique_magic_ptr(magic_open(MAGIC_MIME_TYPE))};

    magic_load(m_cookie.get(), nullptr);

This works fine and `valgrind` says all is good.

Since `magic_t` is a pointer already, and I don't think I can or should use `magic_set`, without `using pointer = magic_t`, I get errors like:

 > cannot convert argument of incomplete type 'magic_t' (aka 'magic_set *') to 'pointer' (aka 'magic_set **') for 1st argument

Do I understand correctly, that `using pointer = magic_t` informs `unique_ptr` "indirectly" via the deleter, that the pointer to be managed actually is `magic_t`?
Is this a valid way to do?