- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
协程定义为 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4628.pdf并在 VS2015/Update 3 中实现,生成器如何调用代表它发出值的函数?
说明示例
我想编写如下代码...
static void yield_for_me()
{
co_yield 27; // does not compile
// co_yield relies on hidden definitions
}
std::experimental::generator<int> testf()
{
yield_for_me();
co_yield 28;
}
...希望它会产生与以下代码完全相同的结果:
std::experimental::generator<int> testf()
{
co_yield 27;
co_yield 28;
}
最佳答案
在函数中使用co_yield
/co_await
/co_return
将其变成一个协程,因此它需要有一个允许编译器的签名发现向编译器解释协程含义的库类。
Visual Studio 附带的生成器不支持将 co_yield
委托(delegate)给另一个生成器。但是创建一个可以的 recursive_generator
并不难。
这是一个 recursive_generator 的例子,它允许产生一个值或不同生成器的执行结果。
https://gist.github.com/GorNishanov/29e813139175b1c5299ad01021d2556d
recursive_generator 的 promise_type 定义了两个 yield_value
函数:
yield_value(T const&); // This one yields individual values
yield_value(recursive_generator<T>&&); // delegates to another generator
使用上面的 recursive_generator,只需将 yield_from_me 函数的返回类型从 void 更改为 recursive_generator 即可。
recursive_generator<int> yield_for_me()
{
co_yield 27;
}
recursive_generator<int> testf()
{
co_yield yield_for_me();
co_yield 28;
}
关于C++ 协程/Visual Studio : How can a generator call a function that yields values on its behalf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42801560/
我正在查看 OAuth2,关于代表流程有一件事我不明白。流程如下所示:我们有: App1(前端) App2(网络 API) App3(数据资源(另一个 Web API)) 假设它们是这样设置的: Ap
我想使用 Twitter API,以便我的程序可以发布一些推文。要使用它,我必须在开发中心注册应用程序并获取一些参数,例如“消费者 key ”、“消费者 secret ”等。然后我可以使用 REST
我正在查看 OAuth2,关于代表流程有一件事我不明白。流程如下所示:我们有: App1(前端) App2(网络 API) App3(数据资源(另一个 Web API)) 假设它们是这样设置的: Ap
我收到了很多“代表”的电子邮件。例如,AddThis 插件从“addThis.com 代表 myfriend@gmail.com”发送电子邮件。 我如何在 C#/ASP.NET 中执行此操作?此外,如
我工作的公司为医疗保健行业提供测试服务。作为我们服务的一部分,我们需要向客户的员工发送电子邮件。通常,这些人是临时工、兼职人员或契约(Contract)工,因此拥有私有(private)电子邮件地址(
我们有一个移动应用程序(ios 和 android),当用户使用 Facebook 登录我们的应用程序时,我们请求以下 Facebook 权限:“offline_access,user_birthda
我试图弄清楚如何使用 MailGun Golang API 发送邮件,而不是“代表”发送邮件。 这是 From 地址当前的样子(其中 foo.com 是发件人的电子邮件域,bar.com 是我的域):
我希望我的 VSTS 扩展(安装在本地 TFS2015.3)能够代表管理员/服务帐户执行特定请求(“代表其他人发出请求”) 背景:我在我的扩展 typescript 中操作(工作项)流程模板,特别是
我想通过添加“代表”地址从我的应用程序发送电子邮件。目前我正在使用 apache common Email 来发送电子邮件,似乎我无法在其中指定发件人。正如我所看到的电子邮件 header ,我需要为
我正在寻找一种方法来代表另一个用户(模拟另一个用户)向工作项添加评论。 VssConnection connection = new VssConnection(new Uri(url
我正在使用 Stripe,并且我已经连接了一个快速帐户。我已经更新了满意的帐户信息,但它仍然受到限制,因为它说我必须接受 tos(服务条款)ni 才能启用所有功能。我用来更新的 api 返回了这个错误
我是“机器学习”的新手,并尝试实现 this question但我不清楚。我已经诱惑了两个月了,所以请帮助我解决我的错误。 实际上,我正在尝试: 从形状的TRAIN_dataset中提取的TRAIN_
Twitter API 允许更新“验证用户的当前状态”,如 the documentation page 中所述。 . 我想要实现的是更新另一个用户的当前状态。考虑杂志的推特帐户。我希望不同的人能够更
协程定义为 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4628.pdf并在 VS2015/Update 3 中实现,生成器如何调
我在 Outlook 中内置了一个自定义表单,可以在任何更改时发送电子邮件通知。由于表单的规范,我不得不在表单中添加一些 VBScript(不幸的是)在表单的关闭事件上发送电子邮件。 该表格目前已发布
我正在开发一个将由客户端应用程序使用的 Web API。我使用的 AD 身份验证机制是“使用应用程序的权限调用 Web API”。 客户端应用程序使用应用程序权限调用 Web API,在 Web AP
我想做的是使用 Microsoft 在 this article 中描述的“Web API 代表流”场景创建一个网络钩子(Hook)。 所以我从 Microsoft github example 开始
您能否告知以下错误的原因以及如何修复它?非常感谢。 我正在使用 Angular 9(前端)Spring Boot(后端)构建一个应用程序,并使用 Azure Active Directory 进行身份
我想做的是使用 Microsoft 在 this article 中描述的“Web API 代表流”场景创建一个网络钩子(Hook)。 所以我从 Microsoft github example 开始
您能否告知以下错误的原因以及如何修复它?非常感谢。 我正在使用 Angular 9(前端)Spring Boot(后端)构建一个应用程序,并使用 Azure Active Directory 进行身份
我是一名优秀的程序员,十分优秀!