最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Are `std::noop_coroutine` and `noop_coroutine_handle` redundant? - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论