hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

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. However, this means a lot of boilerplate code.

Fortunately, this process can be simplified with a re-usable Mixin.

Compiler Explorer link: compiler-explorer.com/z/9YP7sK

@simontoth

if your base type has no distinguished empty value to spare or is not default constructible, I tend to teach to use std::optional<T> to store a resource(handle) in a unique manager type. I'd prefer a named class type instead of a template with boilerplate, but ymmv. templates with many parameters can make debugging harder, since a nice alias tends to be lost in translation.

@PeterSommerlad I agree that I should have wrapped the arguments into an aggregate. Oh well...