{"id":12495,"date":"2017-01-27T16:48:40","date_gmt":"2017-01-27T23:48:40","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=12495"},"modified":"2019-02-18T17:48:44","modified_gmt":"2019-02-18T17:48:44","slug":"yield-keyword-to-become-co_yield-in-vs-2017","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/yield-keyword-to-become-co_yield-in-vs-2017\/","title":{"rendered":"`yield` keyword to become `co_yield` in VS 2017"},"content":{"rendered":"<p>Coroutines\u2014formerly known as \u201c<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/resumable-functions-in-c\/\">C++ resumable functions<\/a>\u201d\u2014are one of the <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/experimental\">Technical Specifications<\/a> (TS) that we have implemented in the Visual C++ compiler. We\u2019ve supported coroutines for three years\u2014ever since the VC++ November 2013 CTP release.<\/p>\n<p>If you\u2019re using coroutines you should be aware that <b>the keyword `yield` is being removed in the release of VS 2017<\/b>. If you use `yield` in your code, you will have to change your code to use the new keyword `co_yield` instead. If you have generators that use `yield expr`, these need to be changed to say `co_yield expr`.<\/p>\n<p>As long as you\u2019re changing your code you might want to migrate from using `await` to `co_await` and from `return` in a coroutine to `co_return`. The Visual C++ compiler accepts all three new keywords today.<\/p>\n<p>For more information about coroutines, please see the Coroutines TS here: <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/n4628.pdf\">http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/n4628.pdf<\/a>. As the author of the Coroutines TS works on the Visual C++ team you can also just send us mail with your questions or feedback (see below.)<\/p>\n<h4>Why are we making this change?<\/h4>\n<p>As a Technical Specification, coroutines have not yet been adopted into the C++ Standard. When the Visual C++ team implemented them in 2013, the feature was implemented as a preview of an up-and-coming C++ feature. The C++ standards committee voted in October of 2015 to change the keywords to include the prefix `co_`. The committee didn\u2019t want to use keywords that would conflict with variable names already in use. `yield`, for example, is used widely in agricultural and financial applications. Also, there are library uses of functions called `yield` in the <a href=\"http:\/\/ericniebler.com\/2014\/04\/27\/range-comprehensions\/\">Ranges TS<\/a> and in the <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/thread\/yield\">thread support library<\/a>.<\/p>\n<p>For reference, here are the keyword mappings that need to be applied to your code.<\/p>\n<p><span style=\"font-size: 12pt\"> <\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\">\n<\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\">\n<\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"><\/span><span style=\"font-size: 12pt\"> <\/span><\/p>\n<table width=\"284\" style=\"line-height: normal;border-collapse: collapse;border-spacing: 2px 2px\">\n<colgroup>\n<col width=\"144\" \/><\/colgroup>\n<colgroup>\n<col width=\"140\" \/><\/colgroup>\n<tbody style=\"vertical-align: middle\">\n<tr style=\"height: 23.25pt;vertical-align: middle\">\n<td width=\"144\" height=\"31\" class=\"xl117\" style=\"border-width: 0.5pt 1pt 1pt 0.5pt;border-style: solid;border-color: black windowtext windowtext black;padding: 1px;vertical-align: bottom\"><span style=\"font-size: 11pt\">Instead of `await`<\/span><\/td>\n<td width=\"140\" class=\"xl118\" style=\"padding: 1px;vertical-align: bottom;border-top-color: black;border-right-color: black;border-bottom-color: windowtext;border-top-width: 0.5pt;border-right-width: 0.5pt;border-bottom-width: 1pt;border-top-style: solid;border-right-style: solid;border-bottom-style: solid\"><span style=\"font-size: 11pt\">Use `co_await`<\/span><\/td>\n<\/tr>\n<tr style=\"height: 23.25pt;vertical-align: middle\">\n<td width=\"144\" height=\"31\" class=\"xl119\" style=\"padding: 1px;vertical-align: bottom;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: black;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 0.5pt;border-right-style: solid;border-bottom-style: solid;border-left-style: solid\"><span style=\"font-size: 11pt\">Instead of `return`<\/span><\/td>\n<td width=\"140\" class=\"xl120\" style=\"padding: 1px;vertical-align: bottom;border-right-color: black;border-bottom-color: windowtext;border-right-width: 0.5pt;border-bottom-width: 1pt;border-right-style: solid;border-bottom-style: solid\"><span style=\"font-size: 11pt\">Use `co_return`<\/span><\/td>\n<\/tr>\n<tr style=\"height: 23.25pt;vertical-align: middle\">\n<td width=\"144\" height=\"31\" class=\"xl121\" style=\"padding: 1px;vertical-align: bottom;border-right-color: windowtext;border-bottom-color: black;border-left-color: black;border-right-width: 1pt;border-bottom-width: 0.5pt;border-left-width: 0.5pt;border-right-style: solid;border-bottom-style: solid;border-left-style: solid\"><span style=\"font-size: 11pt\">Instead of `yield`<\/span><\/td>\n<td width=\"140\" class=\"xl122\" style=\"padding: 1px;vertical-align: bottom;border-right-color: black;border-bottom-color: black;border-right-width: 0.5pt;border-bottom-width: 0.5pt;border-right-style: solid;border-bottom-style: solid\"><span style=\"font-size: 11pt\">Use `co_yield`<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We\u2019re removing the `yield` keyword with VS 2017 because we\u2019re also implementing the Range-v3 TS and we expect many developers to call `yield` after a using declaration for ranges, e.g., `using namespace ::ranges`.<\/p>\n<h4>Preventing these breaks in the future<\/h4>\n<p>We know many of you have taken dependencies on coroutines in your code and understand that this kind of breaking change is difficult. We can\u2019t keep the committee from making changes (trust us, we try!) but at least we can do our best to make sure that you\u2019re not surprised when things do change.<\/p>\n<p>We created a new compiler switch, `\/experimental` when we implemented the <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/12\/03\/c-modules-in-vs-2015-update-1\/\">Modules TS<\/a> in VS 2015 Update 1. You need to include `\/experimental:module` on your command line so that it is clear the feature is experimental and subject to change. If we could go back in time we would have had coroutines enabled with `\/experimental:await` instead of just `\/await` (or `experiemental:coroutine` if we\u2019d known what the feature would be called three years later!)<\/p>\n<p>In a future release <b>we will deprecate the `await` keyword as well as restrict the use of `return` from coroutines <\/b>in favor of the new keywords `co_await` and `co_return`.<\/p>\n<h4>In closing<\/h4>\n<p>As always, we welcome your feedback. Please give us feedback about coroutines in the comments below or through e-mail at <a>visualcpp@microsoft.com<\/a>.<\/p>\n<p>If you encounter other problems with Visual C++ in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. For suggestions, let us know through <a href=\"https:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio-2015\/category\/30937-languages-c\">UserVoice<\/a>. Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Coroutines\u2014formerly known as \u201cC++ resumable functions\u201d\u2014are one of the Technical Specifications (TS) that we have implemented in the Visual C++ compiler. We\u2019ve supported coroutines for three years\u2014ever since the VC++ November 2013 CTP release. If you\u2019re using coroutines you should be aware that the keyword `yield` is being removed in the release of VS 2017. [&hellip;]<\/p>\n","protected":false},"author":316,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[297],"tags":[140,294,295,296,298],"class_list":["post-12495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coroutine","tag-c","tag-co_await","tag-co_return","tag-co_yield","tag-coroutine"],"acf":[],"blog_post_summary":"<p>Coroutines\u2014formerly known as \u201cC++ resumable functions\u201d\u2014are one of the Technical Specifications (TS) that we have implemented in the Visual C++ compiler. We\u2019ve supported coroutines for three years\u2014ever since the VC++ November 2013 CTP release. If you\u2019re using coroutines you should be aware that the keyword `yield` is being removed in the release of VS 2017. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/12495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/316"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=12495"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/12495\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=12495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=12495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=12495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}