2 ms·
> RAII uses destructors. That seems loaded enough in your mind that it aliases to untrue. RAII uses some sort of type-associated operation. How that type assoc
by masklinn 3y ago
> RAII uses destructors.
That seems loaded enough in your mind that it aliases to untrue. RAII uses some sort of type-associated operation. How that type association is reified is up to the language.
> you need special functions for construction and destruction
That is not true. You don't need any special function for construction, and for destruction you only need a hook. Which is no more special (and arguably less so) than the hook you need for either defer or errdefer.
> Destructors are a language feature that is even more ad-hoc than errdefer.
I'm not sure you understand what the expression "ad-hoc" means. "errdefer" is an ad-hoc feature, it has a very narrow and specific purpose. RAII is a much more generic feature, for instance it subsumes both defer and errdefer, as well as other patterns of resource management.
> errdefer is not just used for destroying objects either
Good news: neither is RAII. Object destruction is the hook onto which RAII attaches, not the purpose.