Handle

Introduction

handle.h provides a single type alias:

template <class Allocator>
using OwnedHandle = Own<void, Allocator>;

libx's opaque handles are all typedef void* xFoo (via XDEF_HANDLE). Wrapping them with Own<void, Allocator> is correct but exposes void at every use site. OwnedHandle hides void behind a name that communicates intent: "I own a handle pointer."

Usage

struct EventLoopDestroy {
    void deallocate(void* h, xpp::Layout) const noexcept {
        xEventLoopDestroy(static_cast<xEventLoop>(h));
    }
};

class EventLoop {
    OwnedHandle<EventLoopDestroy> m_loop;
    // Equivalent to: Own<void, EventLoopDestroy> m_loop;
};

The allocator only needs a deallocate(void*, Layout) method — allocate is never called because handles come from the C API (e.g. xEventLoopCreate), not from the allocator. It typically casts to the correct handle type and calls the corresponding xXxxDestroy function. EBO applies — if the allocator is stateless, sizeof(OwnedHandle<Allocator>) == sizeof(void*).