C++ Logo

std-proposals

Advanced search

Re: [std-proposals] void type instantiations

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 13 Oct 2022 23:09:17 -0400
On Thu, Oct 13, 2022 at 10:27 PM Phil Bouchard via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Greetings,
>
> Here's a simple suggestion: void type instantiations. It would be quite useful for singletons and keeping the code cleaner:

I would suggest that "singleton" and "clean code" may not belong in
the same sentence. But in any case:

> int avcodec(...)
> {
>
> static void r1 = avcodec_register_all();
> static void r2 = av_register_all();
>
> [...]
>
> }

What exactly is the purpose of this? Are you just trying to ensure
that a function is only called once? Because we already have that:
`std::call_once`:

int avcodec(...)
{
  static std::once_flag{};
  std::call_once(once_flag, []() {avcodec_register_all(); av_register_all();});
}

Received on 2022-10-14 03:10:43