Daily bit(e) of C++ | Move-only value mixin wrapper
Daily bit(e) of C++ #463, Reducing RAII wrapper boilerplate using a move-only value mixin.
If you interact with legacy or highly portable APIs, you will often encounter various types of handles represented by trivial types.
In C++, we want to wrap these handles in an RAII wrapper to ensure we do not leak resources or access them after they are gone.
For pointer handles, we can use std::unique_ptr and the recently added (C++23) std::out_ptr and std::inout_ptr.
However, if the handle isn't a pointer or is represented by multiple variables (e.g. handle + size), you will be left implementing a boilerplate RAII wrapper.
This process can be simplified with a re-usable Mixin.