c++coroutinec++-coroutine

Are `std::noop_coroutine` and `noop_coroutine_handle` redundant?


In GCC 15, std::noop_coroutine's definition is

{ return std::noop_coroutine_handle(); }

std::noop_coroutine_handle is defined by:

using noop_coroutine_handle = std::coroutine_handle<std::noop_coroutine_promise>;

To get a no-op coroutine, we write

std::noop_coroutine()

which (I guess) is equivalent to

std::noop_coroutine_handle{}

and

std::coroutine_handle<std::noop_coroutine_promise>{}

So I believe the standard library only needs to provide std::noop_coroutine_promise (along with certain specializations that use it as a template parameter).

Why did the standard introduce three new symbols? (Feels a bit arbitrary—just my personal opinion.)


Solution

  • Why did the standard introduce three new symbols?

    Because it can. Defining a particular name in the standard, vs leaving it implementation-defined, only really affects the formatting used to describe it.

    The standard still has to describe the behaviour of the promise type.

    Implementers would have to use some name to define the promise type for noop_coroutine, and the handle type could be written out longhand, but most likely would have an alias.