admin管理员组

文章数量:1356067

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.)

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.)

Share Improve this question edited Mar 28 at 8:50 shynur asked Mar 28 at 5:33 shynurshynur 5122 silver badges11 bronze badges 4
  • 1 Likely for the same reason we got mt19937_64 even though we can just plug the canonical values into mersenne_twister_engine - ergonomics – StoryTeller - Unslander Monica Commented Mar 28 at 5:53
  • @StoryTeller-UnslanderMonica That makes some sense. But it's also important to keep the standard library as clean as possible by minimizing the number of names. I think just keeping std::noop_coroutine might be good enough as well, since we can use std::noop_coroutine() to refer to std::noop_coroutine_handle{} and so on. – shynur Commented Mar 28 at 6:08
  • Is it important to minimise the names in std? It's a namespace. It is reserved for the standard. All the names there are up for grabs. – Caleth Commented Mar 28 at 9:28
  • When I'm looking things up on cppreference, seeing so many names can be overwhelming. Besides, it's always a good idea to be cautious when introducing new names. – shynur Commented Mar 28 at 11:49
Add a comment  | 

1 Answer 1

Reset to default 3

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.

本文标签: cAre stdnoopcoroutine and noopcoroutinehandle redundantStack Overflow