C ++ 1z协程具有语言功能吗? [英] C++1z Coroutines a language feature?

查看:90
本文介绍了C ++ 1z协程具有语言功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么协程(作为最新的C ++ 1z草案)将被实现为核心语言功能(特别的关键字和所有功能)而不是库扩展?

Why will coroutines (as of now in the newest drafts for C++1z) be implemented as a core language feature (fancy keywords and all) as opposed to a library extension?

他们已经有一些实现(Boost.Coroutine等),其中一些实现可以独立于平台,与我阅读的内容无关。委员会为什么决定将其烘焙为核心语言本身?

There already exist a couple of implementations for them (Boost.Coroutine, etc), some of which can be made platform independent, from what i have read. Why has the committee decided to bake it into the core language itself?

我不是说他们不应该这样做,而是Bjarne Stroustrup自己在一些谈话中提到(不要知道再有哪一个)应该尽可能在库中实现新功能,而不要接触核心语言。

I'm not saying they shouldn't but Bjarne Stroustrup himself mentioned in some talk (don't know which one any more) that new features should be implemented in libraries as far as possible instead of touching the core language.

那么,这样做有充分的理由吗?有什么好处?

So is there a good reason to do so? What are the benefits?

推荐答案

尽管有协程的库实现,但它们往往具有特定的限制。例如,在暂停协程时,库实现无法检测到需要维护哪些变量。可以解决此需求,例如,通过以某种形式使使用的变量明确化。但是,当协程应该尽可能地像普通函数一样运行时,应该可以定义局部变量。

While there are library implementation of coroutines, these tend to have specific restrictions. For example, a library implementation cannot detect what variables need to be maintained when a coroutine is suspended. It is possible to work around this need, e.g., by making the used variables explicit in some form. However, when coroutines should behave like normal functions as much as possible, it should be possible to define local variables.

我不认为Boost协程的任何实现者认为它们各自的库接口是理想的。虽然这是目前使用的语言所能达到的最佳效果,但可以改善整体使用。

I don't think any of the implementers of Boost coroutines thinks that their respective library interface is ideal. While it is the best which can be achieved in the currently language, the overall use can be improved.

这篇关于C ++ 1z协程具有语言功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆