├── .gitignore ├── Coroutines ├── EditorReport.md ├── Makefile ├── N4629.html ├── N4629.md ├── N4650.md ├── N4679.md ├── N4737.md ├── README.md ├── back.tex ├── basic.tex ├── compatibility.tex ├── config.tex ├── coroutine-ts-v1.tex ├── cover-reg.tex ├── cover-wd.tex ├── cxx.tex ├── declarations.tex ├── declarators.tex ├── expressions.tex ├── foreword.tex ├── front.tex ├── intro.tex ├── layout.tex ├── lex.tex ├── lib-intro.tex ├── macros.tex ├── overloading.tex ├── p0664r1.html ├── special.tex ├── statements.tex ├── styles.tex ├── support.tex ├── tables.tex └── threads.tex └── r4 ├── r3.docx └── r4.docx /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # tex 20 | *.toc 21 | *.aux 22 | *.out 23 | *.lof 24 | *.lot 25 | *.gz 26 | *.pdf 27 | *.fls 28 | *.fdb_latexmk 29 | *.synctex* 30 | 31 | # External tool builders 32 | .externalToolBuilders/ 33 | 34 | # Locally stored "Eclipse launch configurations" 35 | *.launch 36 | 37 | # CDT-specific 38 | .cproject 39 | 40 | # PDT-specific 41 | .buildpath 42 | 43 | 44 | ################# 45 | ## Visual Studio 46 | ################# 47 | 48 | ## Ignore Visual Studio temporary files, build results, and 49 | ## files generated by popular Visual Studio add-ons. 50 | 51 | # User-specific files 52 | *.suo 53 | *.user 54 | *.sln.docstates 55 | 56 | # Build results 57 | 58 | [Dd]ebug/ 59 | [Rr]elease/ 60 | x64/ 61 | build/ 62 | [Bb]in/ 63 | [Oo]bj/ 64 | 65 | # MSTest test Results 66 | [Tt]est[Rr]esult*/ 67 | [Bb]uild[Ll]og.* 68 | 69 | *_i.c 70 | *_p.c 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.pch 75 | *.pdb 76 | *.pgc 77 | *.pgd 78 | *.rsp 79 | *.sbr 80 | *.tlb 81 | *.tli 82 | *.tlh 83 | *.tmp 84 | *.tmp_proj 85 | *.log 86 | *.vspscc 87 | *.vssscc 88 | .builds 89 | *.pidb 90 | *.log 91 | *.scc 92 | 93 | # Visual C++ cache files 94 | ipch/ 95 | *.aps 96 | *.ncb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | 101 | # Visual Studio profiler 102 | *.psess 103 | *.vsp 104 | *.vspx 105 | 106 | # Guidance Automation Toolkit 107 | *.gpState 108 | 109 | # ReSharper is a .NET coding add-in 110 | _ReSharper*/ 111 | *.[Rr]e[Ss]harper 112 | 113 | # TeamCity is a build add-in 114 | _TeamCity* 115 | 116 | # DotCover is a Code Coverage Tool 117 | *.dotCover 118 | 119 | # NCrunch 120 | *.ncrunch* 121 | .*crunch*.local.xml 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.Publish.xml 141 | *.pubxml 142 | *.publishproj 143 | 144 | # NuGet Packages Directory 145 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 146 | #packages/ 147 | 148 | # Windows Azure Build Output 149 | csx 150 | *.build.csdef 151 | 152 | # Windows Store app package directory 153 | AppPackages/ 154 | 155 | # Others 156 | sql/ 157 | *.Cache 158 | ClientBin/ 159 | [Ss]tyle[Cc]op.* 160 | ~$* 161 | *~ 162 | *.dbmdl 163 | *.[Pp]ublish.xml 164 | *.pfx 165 | *.publishsettings 166 | 167 | # RIA/Silverlight projects 168 | Generated_Code/ 169 | 170 | # Backup & report files from converting an old project file to a newer 171 | # Visual Studio version. Backup files are not needed, because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | App_Data/*.mdf 179 | App_Data/*.ldf 180 | 181 | ############# 182 | ## Windows detritus 183 | ############# 184 | 185 | # Windows image file caches 186 | Thumbs.db 187 | ehthumbs.db 188 | 189 | # Folder config file 190 | Desktop.ini 191 | 192 | # Recycle Bin used on file shares 193 | $RECYCLE.BIN/ 194 | 195 | # Mac crap 196 | .DS_Store 197 | 198 | 199 | ############# 200 | ## Python 201 | ############# 202 | 203 | *.py[cod] 204 | 205 | # Packages 206 | *.egg 207 | *.egg-info 208 | dist/ 209 | build/ 210 | eggs/ 211 | parts/ 212 | var/ 213 | sdist/ 214 | develop-eggs/ 215 | .installed.cfg 216 | 217 | # Installer logs 218 | pip-log.txt 219 | 220 | # Unit test / coverage reports 221 | .coverage 222 | .tox 223 | 224 | #Translations 225 | *.mo 226 | 227 | #Mr Developer 228 | .mr.developer.cfg 229 | *.cb2 230 | *.cb 231 | *.bbl 232 | Coroutines/coroutine-ts-v1.blg 233 | EditorReport.html 234 | -------------------------------------------------------------------------------- /Coroutines/EditorReport.md: -------------------------------------------------------------------------------- 1 | | Document Number: | N4776 | 2 | | -----------------|-------------------------------------------------| 3 | | Date: | 2018-10-07 | 4 | | Project Number: | TS 22277 | 5 | | Audience: | WG21 | 6 | | Reply to: | gorn@microsoft.com | 7 | 8 | 9 | Editor's report for the Coroutines TS 10 | =================================== 11 | 12 | ## New papers 13 | 14 | - N4775 is the current working draft. It replaces N4760. 15 | - N4776 is this Editor's Report for the Coroutines TS. 16 | 17 | ## Changes between N4760 and N4776 18 | 19 | This update only contains editorial changes relative to N4760. 20 | 21 | - updated incorrect cross-referenced that were using C++14 numbering, as opposed to C++17 22 | - added missing endnote marker in [coroutine.handle.resumption] 23 | - fixed off by one clause numbers for [expr.ass], [expr.const], [expr.yield] and [compliance] 24 | - fixed wording for coroutine and setjmp interactions that is now correctly located in [csetjmp.syn] clause 25 | - updated feature test macro to 201806 26 | -------------------------------------------------------------------------------- /Coroutines/Makefile: -------------------------------------------------------------------------------- 1 | ### -*- mode: makefile-gmake -*- 2 | 3 | # Note: If building on Mac OS X, and if you use MacPorts, the following ports 4 | # should be installed: 5 | # 6 | # texlive-latex 7 | # texlive-plain-extra 8 | # texlive-latex-recommended 9 | # texlive-latex-extra 10 | # texlive-fonts-recommended 11 | # texlive-fonts-extra 12 | # texlive-generic-recommended 13 | 14 | TARGET = coroutine-ts-v1 15 | 16 | FIGURES = $(patsubst %.dot,%.pdf,$(wildcard *.dot)) 17 | 18 | TSPDF = pdflatex $(TARGET) | grep -v "^Overfull" 19 | 20 | default: rebuild 21 | 22 | clean: 23 | rm -f *.aux *.idx *.ilg *.ind *.log *.lot *.lof *.tmp *.out *.toc $(TARGET).pdf 24 | 25 | refresh: 26 | $(TSPDF) 27 | 28 | rebuild: 29 | $(TSPDF) 30 | $(TSPDF) 31 | $(TSPDF) 32 | 33 | full: $(FIGURES) grammar xrefs reindex 34 | 35 | %.pdf: %.dot 36 | dot -o $@ -Tpdf $< 37 | 38 | grammar: 39 | sh ../tools/makegram 40 | 41 | xrefs: 42 | sh ../tools/makexref 43 | 44 | # reindex: 45 | # $(TSPDF) 46 | # $(TSPDF) 47 | # $(TSPDF) 48 | # makeindex generalindex 49 | # makeindex libraryindex 50 | # makeindex grammarindex 51 | # makeindex impldefindex 52 | # $(TSPDF) 53 | # $(TSPDF) 54 | 55 | ### Makefile ends here 56 | -------------------------------------------------------------------------------- /Coroutines/N4629.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | N4629 5 | 6 | 292 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 |
Document Number:N4629
Date:2016-11-27
Reply to:gorn@microsoft.com
489 |

Editor's report for the Coroutines TS

490 |

New papers

491 | 493 |

Acknowledgments

494 |

We wish to thank all of the reviewers, including both the Core and Library Working groups.

495 | 496 | 497 | 498 | 499 | -------------------------------------------------------------------------------- /Coroutines/N4629.md: -------------------------------------------------------------------------------- 1 | | Document Number: | N4629 | 2 | | -----------------|-------------------------------------------------| 3 | | Date: | 2016-11-27 | 4 | | Reply to: | gorn@microsoft.com | 5 | 6 | 7 | Editor's report for the Coroutines TS 8 | =================================== 9 | 10 | ## New papers 11 | 12 | - N4628 is the current working draft. It is the initial working draft for the Coroutines TS, based on P0057R7. 13 | - N4629 is this Editor's Report for the current working draft. 14 | 15 | ## Acknowledgments 16 | 17 | We wish to thank all of the reviewers, including both the Core and Library Working groups. 18 | 19 | -------------------------------------------------------------------------------- /Coroutines/N4650.md: -------------------------------------------------------------------------------- 1 | | Document Number: | N4650 | 2 | | -----------------|-------------------------------------------------| 3 | | Date: | 2017-03-02 | 4 | | Reply to: | gorn@microsoft.com | 5 | 6 | 7 | Editor's report for the Coroutines TS 8 | =================================== 9 | 10 | ## New papers 11 | 12 | - N4649 is the current working draft. It replaces N4628. 13 | - N4650 is this Editor's Report for the current working draft. 14 | 15 | ## Notable changes 16 | 17 | Improved wording that allows implementations to omit copying of coroutine parameters. Now paragraph 11 of subclause 8.4.4 states that parameters are always copied and a new bullet in subclause [class.copy] allows to omit the copy if certain conditions are met. 18 | 19 | ## Editorial changes 20 | 21 | - Altered the Clauses 1-4 to conform to ISO guidelines 22 | - Renamed section and subsections to Clauses and subclauses 23 | - Inserted a missing function name in example 8.4.4/12 24 | - Adjusted the date of the feature test macro to 201703 25 | 26 | ## Acknowledgments 27 | 28 | We wish to thank all of the reviewers, including both the Core and Library Working groups. 29 | 30 | -------------------------------------------------------------------------------- /Coroutines/N4679.md: -------------------------------------------------------------------------------- 1 | | Document Number: | N4679 | 2 | | -----------------|-------------------------------------------------| 3 | | Date: | 2017-07-29 | 4 | | Reply to: | gorn@microsoft.com | 5 | 6 | 7 | Editor's report for the Coroutines TS 8 | =================================== 9 | 10 | ## New papers 11 | 12 | - N4680 is the final coroutine TS draft. It replaces N4663. 13 | - N4679 is this Editor's Report for the Coroutines TS. 14 | 15 | ## Notable changes 16 | 17 | - Applied changes from P0664R1 18 | 19 | ## Editorial changes 20 | 21 | - Replaced PDTS on the front page with TS. 22 | - Proposed wording for issue 15 missed adding constexpr to declarations of comparison operators in synopsis. Fixed by adding constexpr to the declarations in synopsis. 23 | - Fixed typo in resolution of issue 23: "`coroutine_handle "`coroutine_handle`". 24 | - Moved example from paragraph 8.4.4/12 to paragraph 8.4.4/8 where it belongs. A year ago paragraph 12 was reordered to be paragraph 8, but the related example was not moved and stayed attached to the wrong paragraph. Fixed now. 25 | - Adjusted the date of the feature test macro to 201707 26 | - Removed the acknowledgements paragraph 4.1 27 | - Reworded 18.11.1/2 from: 28 | - A program may specialize this template. Such specialization shall define a publicly accessible nested type named \tcode{promise_type}. 29 | to 30 | - All specializations of this template shall define a publicly accessible nested type named \tcode{promise_type}. 31 | - Reworded 18.11.2/2 from: 32 | - The behavior of a program that adds specializations for \tcode{coroutine_handle} is undefined. 33 | to 34 | - If a program declares an explicit or partial specialization of \tcode{coroutine_handle}, the behavior is undefined. 35 | 36 | ## Acknowledgments 37 | 38 | We wish to thank all of the reviewers as well as editing committee members: Geoffrey Romer, Bryce Lelbach, and Marshall Clow. 39 | 40 | -------------------------------------------------------------------------------- /Coroutines/N4737.md: -------------------------------------------------------------------------------- 1 | | Document Number: | N4737 | 2 | | -----------------|-------------------------------------------------| 3 | | Date: | 2018-03-27 | 4 | | Project Number: | TS 22277 | 5 | | Audience: | WG21 | 6 | | Reply to: | gorn@microsoft.com | 7 | 8 | 9 | Editor's report for the Coroutines TS 10 | =================================== 11 | 12 | ## New papers 13 | 14 | - N4736 is the current working draft. It replaces N4723. 15 | - N4737 is this Editor's Report for the Coroutines TS. 16 | 17 | ## Changes between N4736 and N4723 18 | 19 | - Applied changes from p0913r1 "Add symmetric coroutine control transfer" 20 | - Applied changes from p0914r1 "Add coroutine parameter preview" 21 | - Applied changes from p0911r1 "Rebase coroutine TS to C++17" 22 | 23 | ## Editorial changes 24 | 25 | - In comments in synopsis of coroutine handle, reference to a section goes before the rest of the text (for consistency with other comments): 26 | ``` 27 | before: // noop coroutine promise 21.11.3 28 | after: // 21.11.3 noop coroutine promise 29 | ``` 30 | - In Effects and Returns clauses, add period at the end: 31 | ``` 32 | before: Effects: None 33 | after: Effects: None. 34 | 35 | before: Returns: true 36 | after: Returns: true. 37 | ``` 38 | -------------------------------------------------------------------------------- /Coroutines/README.md: -------------------------------------------------------------------------------- 1 | wording for coroutine proposal 2 | -------------------------------------------------------------------------------- /Coroutines/back.tex: -------------------------------------------------------------------------------- 1 | 2 | % 3 | -------------------------------------------------------------------------------- /Coroutines/basic.tex: -------------------------------------------------------------------------------- 1 | 2 | %sdf sad 3 | \rSec0[basic]{Basic concepts} 4 | 5 | \setcounter{section}{6} 6 | %\rSec1[basic.start]{Start and termination} 7 | 8 | \rSec2[basic.start.main]{Main function} 9 | 10 | Add underlined text to paragraph 3. 11 | 12 | \begin{quote} 13 | \setcounter{Paras}{2} 14 | 15 | \pnum 16 | The function \tcode{main} shall not be used within 17 | a program. 18 | \indextext{\idxcode{main()}!implementation-defined linkage~of}% 19 | The linkage~(\cxxref{basic.link}) of \tcode{main} is 20 | \impldef{linkage of \tcode{main}}. A program that defines \tcode{main} as 21 | deleted or that declares \tcode{main} to be 22 | \tcode{inline,} \tcode{static}, or \tcode{constexpr} is ill-formed. 23 | \added{The function \tcode{main} shall not be a coroutine (\ref{dcl.fct.def.coroutine}).} ... 24 | %The name \tcode{main} is 25 | %not otherwise reserved. \enterexample member functions, classes, and 26 | %enumerations can be called \tcode{main}, as can entities in other 27 | %namespaces. \exitexample 28 | \end{quote} 29 | 30 | \setcounter{section}{7} 31 | \setcounter{subsection}{4} 32 | \rSec3[basic.stc.dynamic.allocation]{Allocation functions} 33 | 34 | Modify paragraph 4 as follows: 35 | 36 | \begin{quote} 37 | \setcounter{Paras}{3} 38 | \pnum 39 | 40 | A global allocation function is only called as the result of a new 41 | expression~(\cxxref{expr.new}), or called directly using the function call 42 | syntax~(\cxxref{expr.call}), 43 | \added{or called indirectly to allocate storage for a coroutine frame (\ref{dcl.fct.def.coroutine}),} 44 | or called indirectly through calls to the 45 | functions in the \Cpp standard library. \enternote In particular, a 46 | global allocation function is not called to allocate storage for objects 47 | with static storage duration~(\cxxref{basic.stc.static}), for objects or references 48 | with thread storage duration~(\cxxref{basic.stc.thread}), for objects of 49 | type \tcode{std::type_info}~(\cxxref{expr.typeid}), or for an 50 | exception object~(\cxxref{except.throw}). 51 | \exitnote 52 | \end{quote} 53 | 54 | %\setcounter{section}{6} 55 | %\rSec1[basic.stc]{Storage duration} 56 | %\setcounter{subsection}{4} 57 | %%\rSec2[basic.stc.dynamic]{Dynamic storage duration}% 58 | %\rSec3[basic.stc.dynamic.allocation]{Allocation functions} 59 | %Add underlined text to paragraph 1. 60 | % 61 | %\begin{quote} 62 | %\pnum 63 | %\indextext{function!allocation}% 64 | %An allocation function shall be a class member function or a global 65 | %function; a program is ill-formed if an allocation function is declared 66 | %in a namespace scope other than global scope or declared static in 67 | %global scope. The return type shall be \tcode{void*}. The first 68 | %parameter shall have type \tcode{std::size_t}~(\cxxref{support.types}). The 69 | %first parameter shall not have an associated default 70 | %argument~(\cxxref{dcl.fct.default}). The value of the first parameter shall 71 | %be interpreted as the requested size of the allocation. An allocation 72 | %function can be a function template. Such a template shall declare its 73 | %return type and first parameter as specified above (that is, template 74 | %parameter types shall not be used in the return type and first parameter 75 | %type). Template allocation functions shall have two or more parameters. 76 | %\added{An allocation function with exactly one argument is a usual allocation function.} 77 | %\end{quote} 78 | 79 | \begingroup 80 | \renewcommand{\cleardoublepage}{} 81 | \renewcommand{\clearpage}{} 82 | \rSec0[conv]{Standard Conversions} 83 | \endgroup 84 | No changes are made to Clause \ref{conv} of the \Cpp Standard. 85 | -------------------------------------------------------------------------------- /Coroutines/compatibility.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | \infannex{diff}{Compatibility} 3 | 4 | \rSec1[diff.iso]{\Cpp extensions for Coroutine Functions and ISO \Cpp 2014} 5 | 6 | \pnum 7 | This subclause lists the differences between \Cpp with Concepts 8 | and ISO \Cpp, by the chapters of this document. 9 | 10 | \rSec2[diff.lex]{Clause~\ref{lex}: lexical conventions} 11 | 12 | \ref{lex.key} 13 | \change New Keywords\\ 14 | New keywords are added to \Cpp extensions for coroutines; 15 | see \ref{lex.key}. 16 | \rationale 17 | These keywords were added in order to implement the semantics of the 18 | new features. In particular, the \tcode{yield} keyword is added 19 | to allow a function to yield zero or more values prior to completion. The \tcode{await-keyword} keyword is 20 | added to enable a suspension of a coroutine while 21 | awaiting on completion of asynchronous computation. 22 | \effect 23 | Change to semantics of well-defined feature. 24 | Any ISO \Cpp programs that used any of these keywords as identifiers 25 | are not valid \Cpp programs with coroutines. 26 | \difficulty 27 | Syntactic transformation. 28 | Converting one specific program is easy. 29 | Converting a large collection 30 | of related programs takes more work. 31 | \howwide 32 | Seldom. 33 | 34 | -------------------------------------------------------------------------------- /Coroutines/config.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | %%-------------------------------------------------- 3 | %% Version numbers 4 | \newcommand{\docno}{N4775} 5 | \newcommand{\prevdocno}{N4760} 6 | \newcommand{\cppver}{201606L} 7 | 8 | %% Release date 9 | \newcommand{\reldate}{\today} 10 | %\newcommand{\reldate}{2015-03-23} 11 | 12 | %% Library chapters 13 | \newcommand{\firstlibchapter}{language.support} 14 | \newcommand{\lastlibchapter}{thread} 15 | 16 | %% Document title 17 | \newcommand{\doctitle}{\Cpp Extensions for Coroutines} 18 | \newcommand{\frtitle}{Extensions \Cpp pour les Coroutines} 19 | -------------------------------------------------------------------------------- /Coroutines/coroutine-ts-v1.tex: -------------------------------------------------------------------------------- 1 | %% main file for the C++ standard. 2 | %% 3 | 4 | %%-------------------------------------------------- 5 | %% basics 6 | \documentclass[ebook,10pt,oneside,openany,final]{memoir} 7 | 8 | \usepackage[american] 9 | {babel} % needed for iso dates 10 | \usepackage[iso,american] 11 | {isodate} % use iso format for dates 12 | \usepackage[final] 13 | {listings} % code listings 14 | \usepackage[color] % change bars 15 | {changebar} 16 | \usepackage{longtable} % auto-breaking tables 17 | \usepackage{ltcaption} % fix captions for long tables 18 | \usepackage{booktabs} % fancy tables 19 | \usepackage{relsize} % provide relative font size changes 20 | \usepackage{underscore} % remove special status of '_' in ordinary text 21 | \usepackage{verbatim} % improved verbatim environment 22 | \usepackage{parskip} % handle non-indented paragraphs "properly" 23 | \usepackage{array} % new column definitions for tables 24 | \usepackage[normalem]{ulem} 25 | \usepackage{color} % define colors for strikeouts and underlines 26 | \usepackage{amsmath} % additional math symbols 27 | \usepackage{mathrsfs} % mathscr font 28 | \usepackage{multicol} 29 | \usepackage{xspace} 30 | \usepackage{fixme} 31 | \usepackage{lmodern} 32 | \usepackage[T1]{fontenc} 33 | \usepackage[pdftex, final]{graphicx} 34 | \usepackage[pdftex, 35 | pdftitle={C++ Technical Specification}, 36 | pdfsubject={C++ Technical Specification}, 37 | pdfcreator={Gor Nishanov}, 38 | bookmarks=true, 39 | bookmarksnumbered=true, 40 | pdfpagelabels=true, 41 | pdfpagemode=UseOutlines, 42 | pdfstartview=FitH, 43 | linktocpage=true, 44 | colorlinks=true, 45 | linkcolor=blue, 46 | plainpages=false 47 | ]{hyperref} 48 | \usepackage{memhfixc} % fix interactions between hyperref and memoir 49 | \usepackage{xstring} 50 | 51 | \input{layout} 52 | \input{styles} 53 | \input{macros} 54 | \input{tables} 55 | \input{cxx} 56 | 57 | 58 | %%-------------------------------------------------- 59 | %% fix interaction between hyperref and other 60 | %% commands 61 | \pdfstringdefDisableCommands{\def\smaller#1{#1}} 62 | \pdfstringdefDisableCommands{\def\textbf#1{#1}} 63 | \pdfstringdefDisableCommands{\def\raisebox#1{}} 64 | \pdfstringdefDisableCommands{\def\hspace#1{}} 65 | 66 | %%-------------------------------------------------- 67 | %% add special hyphenation rules 68 | \hyphenation{tem-plate ex-am-ple in-put-it-er-a-tor name-space name-spaces} 69 | 70 | \begin{document} 71 | \chapterstyle{cppstd} 72 | \pagestyle{cpppage} 73 | 74 | %%-------------------------------------------------- 75 | %% configuration 76 | \input{config} 77 | 78 | %%-------------------------------------------------- 79 | %% front matter 80 | \frontmatter 81 | \include{front} 82 | 83 | %%-------------------------------------------------- 84 | %% main body of the document 85 | \mainmatter 86 | \setglobalstyles 87 | 88 | %\input{foreword} 89 | \input{intro} 90 | \input{lex} 91 | \input{basic} 92 | \input{expressions} 93 | \input{statements} 94 | \input{declarations} 95 | \input{declarators} 96 | 97 | \begingroup 98 | \renewcommand{\cleardoublepage}{} 99 | \renewcommand{\clearpage}{} 100 | \rSec0[class]{Classes} 101 | \endgroup 102 | No changes are made to Clause \ref{class} of the \Cpp Standard. 103 | 104 | \begingroup 105 | \renewcommand{\cleardoublepage}{} 106 | \renewcommand{\clearpage}{} 107 | \rSec0[class.derived]{Derived classes} 108 | \endgroup 109 | No changes are made to Clause \ref{class.derived} of the \Cpp Standard. 110 | 111 | \begingroup 112 | \renewcommand{\cleardoublepage}{} 113 | \renewcommand{\clearpage}{} 114 | \rSec0[class.access]{Member Access Control} 115 | \endgroup 116 | 117 | No changes are made to Clause \ref{class.access} of the \Cpp Standard. 118 | \input{special} 119 | \input{overloading} 120 | \begingroup 121 | \renewcommand{\cleardoublepage}{} 122 | \renewcommand{\clearpage}{} 123 | \rSec0[temp]{Templates} 124 | \endgroup 125 | No changes are made to Clause \ref{temp} of the \Cpp Standard. 126 | 127 | \begingroup 128 | \renewcommand{\cleardoublepage}{} 129 | \renewcommand{\clearpage}{} 130 | \rSec0[except]{Exception handling} 131 | \endgroup 132 | No changes are made to Clause \ref{except} of the \Cpp Standard. 133 | 134 | \begingroup 135 | \renewcommand{\cleardoublepage}{} 136 | \renewcommand{\clearpage}{} 137 | \rSec0[cpp]{Preprocessing directives} 138 | \endgroup 139 | No changes are made to Clause \ref{cpp} of the \Cpp Standard. 140 | \input{lib-intro} 141 | \input{support} 142 | \input{threads} 143 | 144 | %%-------------------------------------------------- 145 | %% appendices 146 | 147 | %\appendix 148 | %\include{compatibility} 149 | 150 | %%-------------------------------------------------- 151 | %% back matter 152 | \backmatter 153 | \include{back} 154 | 155 | 156 | %%-------------------------------------------------- 157 | %% End of document 158 | \end{document} 159 | -------------------------------------------------------------------------------- /Coroutines/cover-reg.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | %%-------------------------------------------------- 3 | %% Title page for the C++ Standard 4 | 5 | 6 | \thispagestyle{empty} 7 | {\raisebox{.35ex}{\smaller\copyright}}\,ISO 2017 --- All rights reserved 8 | \vspace{2ex} 9 | 10 | \begin{flushright} 11 | \textbf{ISO/IEC JTC1 SC22 WG21 \,\LARGE\docno} %prev 4663 12 | 13 | Date: \reldate 14 | 15 | ISO/IEC TS 22277 16 | 17 | ISO/IEC JTC1 SC22 18 | 19 | Secretariat: ANSI 20 | 21 | \end{flushright} 22 | 23 | \vfill 24 | 25 | \textbf{\LARGE Programming Languages --- \doctitle} 26 | 27 | Langages de programmation --- \frtitle 28 | 29 | \vfill 30 | 31 | \begin{tabular}{|p{\hsize}|} 32 | \hline 33 | \begin{center} 34 | \textbf{Warning} 35 | \end{center} 36 | 37 | \vspace{2ex} 38 | 39 | This document is not an ISO International Standard. It is distributed 40 | for review and comment. It is subject to change without notice and may 41 | not be referred to as an International Standard.\\\\ 42 | 43 | Recipients of this draft are invited to submit, with their comments, 44 | notification of any relevant patent rights of which they are aware 45 | and to provide supporting documentation.\\\\ 46 | \hline 47 | \end{tabular} 48 | 49 | \vfill 50 | \noindent 51 | Document type: Proposed Draft Technical Specification\\ 52 | Document stage: (30) Committee\\ 53 | Document Language: E 54 | \pagebreak 55 | 56 | \thispagestyle{cpppage} 57 | 58 | \begin{tabular}{|p{\hsize}|} 59 | \hline 60 | \begin{center} 61 | \textbf{Copyright notice} 62 | \end{center} 63 | 64 | \vspace{2ex} 65 | 66 | All rights reserved. Unless otherwise specified, 67 | no part of this publication may be reproduced or 68 | utilized otherwise in any form or by any means, 69 | electronic or mechanical, including photocopying, 70 | or posting on the internet or an intranet, 71 | without prior written permission. 72 | Permission can be requested 73 | from either ISO at the address below 74 | or ISO's member body in the country of the requester.\\\\ 75 | 76 | \begin{minipage}{\hsize} 77 | \begin{indented} 78 | % \microtypesetup{activate=false}% 79 | ISO copyright office\\ 80 | Case postale 56, CH-1211 Geneva 20\\ 81 | \rlap{Tel.}\hphantom{Fax} + 41 22 749 01 11\\ 82 | Fax + 41 22 749 09 47\\ 83 | E-mail copyright@iso.org\\ 84 | Web www.iso.org 85 | \end{indented} 86 | \end{minipage} 87 | \\\\ 88 | \hline 89 | \end{tabular} 90 | 91 | \newpage 92 | -------------------------------------------------------------------------------- /Coroutines/cover-wd.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | %%-------------------------------------------------- 3 | %% Title page for the C++ Standard 4 | 5 | 6 | \thispagestyle{empty} 7 | \begingroup 8 | \def\hd{\begin{tabular}{ll} 9 | \textbf{Document Number:} & {\larger\docno} \\ 10 | \textbf{Date:} & \reldate \\ 11 | \textbf{Revises:} & \prevdocno \\ 12 | \textbf{Reply to:} & Gor Nishanov 13 | \end{tabular} 14 | } 15 | \newlength{\hdwidth} 16 | \settowidth{\hdwidth}{\hd} 17 | \hfill\begin{minipage}{\hdwidth}\hd\end{minipage} 18 | \endgroup 19 | 20 | \vspace{2.5cm} 21 | \begin{center} 22 | \textbf{\Huge 23 | Working Draft, 24 | %Technical Specification for 25 | \Cpp Extensions for Coroutines} 26 | %\textbf{\Huge 27 | % (Revision 3)} 28 | \end{center} 29 | \vfill 30 | \textbf{Note: this is an early draft. It's known to be incomplet and 31 | incorrekt, and it has lots of 32 | b\kern-1.2pta\kern1ptd\hspace{1.5em}for\kern-3ptmat\kern0.6ptti\raise0.15ex\hbox{n}g.} 33 | \newpage 34 | -------------------------------------------------------------------------------- /Coroutines/cxx.tex: -------------------------------------------------------------------------------- 1 | 2 | % Define section from the C++ standard that can be indexed 3 | % using its dotted identifer. That is: 4 | % 5 | % \cxxsec{basic.def.odr}{3.2} 6 | % 7 | % This is used to make references to sections of the C++ Standard 8 | % that are not labeled within this document. 9 | \newcommand{\cxxsec}[2]{% 10 | \expandafter\def\csname #1 \endcsname{#2}% 11 | } 12 | 13 | % Generate a reference to the section with the given id. This 14 | % expands to the full chapter/section/subsection number declared 15 | % by \cxxsec. For example: 16 | % 17 | % \cxxref{basic.def.odr} 18 | % 19 | % Expands to the string 3.2. 20 | \newcommand{\cxxref}[1]{% 21 | \csname #1 \endcsname% 22 | } 23 | \newcommand{\iref}[1]{\nolinebreak[3] (\cxxref{#1})} 24 | 25 | \cxxsec{intro.compliance}{4.1} 26 | \cxxsec{intro.execution}{4.6} 27 | \cxxsec{lex.key}{5.11} 28 | \cxxsec{basic.link}{6.5} 29 | \cxxsec{basic.def.odr}{6.2} 30 | \cxxsec{basic.scope.namespace}{6.3.6} 31 | \cxxsec{basic.lookup}{6.4} 32 | \cxxsec{basic.lookup.unqual}{6.4.1} 33 | \cxxsec{basic.lookup.argdep}{6.4.2} 34 | \cxxsec{basic.lookup.classref}{6.4.5} 35 | \cxxsec{basic.start.main}{6.6.1} 36 | \cxxsec{basic.stc.static}{6.7.1} 37 | \cxxsec{basic.stc.thread}{6.7.2} 38 | \cxxsec{basic.stc.auto}{6.7.3} 39 | \cxxsec{basic.stc.dynamic.allocation}{6.7.4.1} 40 | \cxxsec{basic.stc.dynamic.deallocation}{6.7.4.2} 41 | \cxxsec{basic.types}{6.9} 42 | \cxxsec{basic.fundamental}{6.9.1} 43 | \cxxsec{basic.compound}{6.9.2} 44 | 45 | \cxxsec{conv}{7} 46 | 47 | \cxxsec{expr}{8} 48 | \cxxsec{expr.prim}{8.1} 49 | \cxxsec{expr.prim.lambda}{8.1.5} 50 | \cxxsec{expr.call}{8.2.2} 51 | \cxxsec{expr.typeid}{8.2.8} 52 | \cxxsec{expr.unary}{8.3} 53 | \cxxsec{expr.unary.op}{8.3.1} 54 | \cxxsec{expr.pre.incr}{8.3.2} 55 | \cxxsec{expr.sizeof}{8.3.3} 56 | \cxxsec{expr.new}{8.3.4} 57 | \cxxsec{expr.delete}{8.3.5} 58 | \cxxsec{expr.alignof}{8.3.6} 59 | \cxxsec{expr.unary.noexcept}{8.3.7} 60 | \cxxsec{expr.cast}{8.4} 61 | \cxxsec{expr.mptr.oper}{8.5} 62 | \cxxsec{expr.mul}{8.6} 63 | \cxxsec{expr.add}{8.7} 64 | \cxxsec{expr.shift}{8.8} 65 | \cxxsec{expr.rel}{8.9} 66 | \cxxsec{expr.eq}{8.10} 67 | \cxxsec{expr.bit.and}{8.11} 68 | \cxxsec{expr.bit.xor}{8.12} 69 | \cxxsec{expr.bit.or}{8.13} 70 | \cxxsec{expr.log.and}{8.14} 71 | \cxxsec{expr.log.or}{8.15} 72 | \cxxsec{expr.cond}{8.16} 73 | \cxxsec{expr.ass}{8.18} 74 | \cxxsec{expr.comma}{8.19} 75 | \cxxsec{expr.const}{8.20} 76 | 77 | \cxxsec{stmt.block}{9.3} 78 | \cxxsec{stmt.select}{9.4} 79 | \cxxsec{stmt.iter}{9.5} 80 | \cxxsec{stmt.for}{9.5.3} 81 | \cxxsec{stmt.ranged}{9.5.4} 82 | \cxxsec{stmt.return}{9.6.3} 83 | \cxxsec{stmt.ambig}{9.8} 84 | 85 | \cxxsec{dcl.dcl}{10} 86 | \cxxsec{dcl.spec}{10.1} 87 | \cxxsec{dcl.fct.spec}{10.1.2} 88 | \cxxsec{dcl.constexpr}{10.1.5} 89 | \cxxsec{dcl.type}{10.1.7} 90 | \cxxsec{dcl.type.cv}{10.1.7.1} 91 | \cxxsec{dcl.type.simple}{10.1.7.2} 92 | \cxxsec{dcl.type.elab}{10.1.7.3} 93 | \cxxsec{dcl.spec.auto}{10.1.7.4} 94 | 95 | \cxxsec{dcl.decl}{11} 96 | \cxxsec{dcl.name}{11.1} 97 | \cxxsec{dcl.ambig.res}{11.2} 98 | \cxxsec{dcl.meaning}{11.3} 99 | \cxxsec{dcl.fct}{11.3.5} 100 | \cxxsec{dcl.fct.default}{11.3.6} 101 | \cxxsec{dcl.fct.def}{11.4} 102 | \cxxsec{dcl.fct.def.general}{11.4.1} 103 | \cxxsec{dcl.init.list}{11.6.4} 104 | 105 | \cxxsec{class}{12} 106 | \cxxsec{class.name}{12.1} 107 | \cxxsec{class.mem}{12.2} 108 | \cxxsec{class.static.data}{12.2.3.2} 109 | 110 | \cxxsec{class.derived}{13} 111 | \cxxsec{class.mi}{13.1} 112 | \cxxsec{class.member.lookup}{13.2} 113 | \cxxsec{class.virtual}{13.3} 114 | \cxxsec{class.abstract}{13.4} 115 | 116 | \cxxsec{class.ctor}{15.1} 117 | \cxxsec{class.temporary}{15.2} 118 | \cxxsec{class.dtor}{15.4} 119 | \cxxsec{class.copy}{15.8} 120 | 121 | \cxxsec{over}{16} 122 | \cxxsec{over.load}{16.1} 123 | \cxxsec{over.dcl}{16.2} 124 | \cxxsec{over.match}{16.3} 125 | \cxxsec{over.match.oper}{16.3.1.2} 126 | \cxxsec{over.match.funcs}{16.3.1} 127 | \cxxsec{over.match.viable}{16.3.2} 128 | \cxxsec{over.match.best}{16.3.3} 129 | \cxxsec{over.over}{16.4} 130 | \cxxsec{over.oper}{16.5} 131 | \cxxsec{over.call}{16.5.4} 132 | \cxxsec{over.built}{16.6} 133 | 134 | \cxxsec{temp}{17} 135 | \cxxsec{temp.param}{17.1} 136 | \cxxsec{temp.names}{17.2} 137 | \cxxsec{temp.arg}{17.3} 138 | \cxxsec{temp.arg.type}{17.3.1} 139 | \cxxsec{temp.arg.nontype}{17.3.2} 140 | \cxxsec{temp.arg.template}{17.3.3} 141 | \cxxsec{temp.type}{17.4} 142 | \cxxsec{temp.decls}{17.5} 143 | \cxxsec{temp.class}{17.5.1} 144 | \cxxsec{temp.mem.func}{17.5.1.1} 145 | \cxxsec{temp.mem.class}{17.5.1.2} 146 | \cxxsec{temp.static}{17.5.1.3} 147 | \cxxsec{temp.mem.enum}{17.5.1.4} 148 | \cxxsec{temp.mem}{17.5.2} 149 | \cxxsec{temp.variadic}{17.5.3} 150 | \cxxsec{temp.friend}{17.5.4} 151 | \cxxsec{temp.class.spec.match}{17.5.5.1} 152 | \cxxsec{temp.class.order}{17.5.5.2} 153 | \cxxsec{temp.class.spec.mfunc}{17.5.5.3} 154 | \cxxsec{temp.fct}{17.5.6} 155 | \cxxsec{temp.over.link}{17.5.6.1} 156 | \cxxsec{temp.func.order}{17.5.6.2} 157 | \cxxsec{temp.res}{17.6} 158 | \cxxsec{temp.local}{17.6.1} 159 | \cxxsec{temp.dep}{17.6.2} 160 | \cxxsec{temp.dep.type}{17.6.2.1} 161 | \cxxsec{temp.dep.expr}{17.6.2.2} 162 | \cxxsec{temp.dep.constexpr}{17.6.2.3} 163 | \cxxsec{temp.dep.temp}{17.6.2.4} 164 | \cxxsec{temp.nondep}{17.6.3} 165 | \cxxsec{temp.dep.res}{17.6.4} 166 | \cxxsec{temp.inject}{17.6.5} 167 | \cxxsec{temp.spec}{17.7} 168 | \cxxsec{temp.inst}{17.7.1} 169 | \cxxsec{temp.explicit}{17.7.2} 170 | \cxxsec{temp.expl.spec}{17.7.3} 171 | 172 | \cxxsec{temp.deduct}{17.9.2} 173 | \cxxsec{temp.deduct.call}{17.9.2.1} 174 | \cxxsec{temp.deduct.funcaddr}{17.9.2.2} 175 | \cxxsec{temp.deduct.conv}{17.9.2.3} 176 | \cxxsec{temp.deduct.partial}{17.9.2.4} 177 | \cxxsec{temp.deduct.type}{17.9.2.5} 178 | \cxxsec{temp.deduct.decl}{17.9.2.6} 179 | 180 | \cxxsec{except}{18} 181 | \cxxsec{except.throw}{18.1} 182 | \cxxsec{except.ctor}{18.2} 183 | \cxxsec{except.handle}{18.3} 184 | \cxxsec{except.spec}{18.4} 185 | \cxxsec{except.special}{18.5} 186 | \cxxsec{except.terminate}{18.5.1} 187 | \cxxsec{except.uncaught}{18.5.2} 188 | 189 | \cxxsec{allocator.requirements}{20.5.3.5} 190 | 191 | \cxxsec{support.types}{21.2} 192 | \cxxsec{support.limits}{21.3} 193 | \cxxsec{cstdint}{21.4} 194 | \cxxsec{support.start.term}{21.5} 195 | \cxxsec{support.dynamic}{21.6} 196 | \cxxsec{support.rtti}{21.7} 197 | \cxxsec{support.exception}{21.8} 198 | \cxxsec{support.initlist}{21.9} 199 | \cxxsec{support.runtime}{21.10} 200 | 201 | \cxxsec{unord.hash}{23.14.15} 202 | \cxxsec{meta}{23.15} 203 | \cxxsec{atomics}{32} 204 | -------------------------------------------------------------------------------- /Coroutines/declarations.tex: -------------------------------------------------------------------------------- 1 | 2 | %% 3 | %% Declarations 4 | %% 5 | \rSec0[dcl.dcl]{Declarations} 6 | 7 | \rSec1[dcl.spec]{Specifiers} 8 | %% 9 | %% constexpr specifier 10 | %% 11 | \setcounter{section}{1} 12 | \setcounter{subsection}{4} 13 | \rSec2[dcl.constexpr]{The \tcode{constexpr} specifier}% 14 | 15 | Insert a new bullet after paragraph 3 bullet 1. 16 | 17 | %Add the underlined text as the last item in the list in paragraph 3. Note that 18 | %the preceding (unmodified) items in the \Cpp Standard are elided in this 19 | %document. 20 | 21 | \begin{quote} 22 | \setcounter{Paras}{2} 23 | \pnum 24 | \indextext{specifier!\idxcode{constexpr}!function} 25 | \indextext{constexpr function} 26 | The definition of a \tcode{constexpr} function shall satisfy the following 27 | constraints: 28 | 29 | \begin{itemize} 30 | \item it shall not be virtual~(\cxxref{class.virtual}); 31 | \item \added{it shall not be a coroutine (\ref{dcl.fct.def.coroutine})}; 32 | \item \ldots 33 | \end{itemize} 34 | \end{quote} 35 | 36 | %\ednote{ 37 | % Though in the current proposal we do not allow constexpr coroutines, 38 | % we envision that generator style coroutines with yield statements 39 | % can be constexpr with some restrictions. 40 | % The following example is a part of this editorial note and should not be included in the \Cpp standard.} 41 | % 42 | %\enterexample \tcode{constexpr} \textit{pack generators} looks promising and may be explored in the future in a separate proposal. The teaser snippet: 43 | % 44 | %\begin{codeblock} 45 | % constexpr auto int_range(int from, int to_excl) { 46 | % for (int k = from; k}, where \tcode{T} is deduced from the \grammarterm{yield-expression}{}s as if a \grammarterm{yield-expression} were a \tcode{return} statement in a function with declared type \tcode{auto} without a \grammarterm{trailing-return-type}. 108 | % 109 | %%NOTE Jens text 110 | % 111 | %\item Otherwise, if an \grammarterm{await-expression} is present in a function, then 112 | %the return type is\linebreak \tcode{std::task} where type \tcode{T} is deduced from 113 | %\tcode{return} statements as if the \tcode{return} statements were in a function with declared type \tcode{auto} without a \grammarterm{trailing-return-type}. 114 | % 115 | %\item Otherwise, if a \grammarterm{yield-expression} is present in a function, then the return type is \linebreak 116 | %\tcode{std::generator}, 117 | %where \tcode{T} is deduced from the \grammarterm{yield-expression}{}s as if a \grammarterm{yield-expression} were a \tcode{return} statement in a function with declared type \tcode{auto} without a \grammarterm{trailing-return-type}. 118 | % 119 | %\end{itemize} 120 | %\enterexample 121 | %\begin{codeblock} 122 | %// deduces to std::generator 123 | %auto f() { for(auto ch: "Hello") co_yield ch; } 124 | % 125 | %// deduces to std::async_stream 126 | %auto ticks() { 127 | % for(int tick = 0;; ++tick) { 128 | % co_yield tick; 129 | % co_await sleep_for(1ms); 130 | % } 131 | %} 132 | % 133 | %future g(); 134 | % 135 | %// deduces to std::task 136 | %auto f2() { co_await g(); } 137 | % 138 | % 139 | %// deduces to std::task 140 | %auto f3() { 141 | % co_await g(); 142 | % return 42; 143 | %} 144 | % 145 | %\end{codeblock} 146 | %\exitexample 147 | % 148 | %\pnum 149 | %The templates \tcode{std::generator}, 150 | %\tcode{std::task}, and \linebreak 151 | %\tcode{std::async_stream} are not predefined; 152 | %if the appropriate headers are not included prior to a use --- even an implicit use in which the type is not 153 | %named~(\ref{dcl.spec.auto}) --- the program is ill-formed. 154 | %\end{quote} 155 | -------------------------------------------------------------------------------- /Coroutines/declarators.tex: -------------------------------------------------------------------------------- 1 | 2 | %% 3 | %% Declarators 4 | %% 5 | \begingroup 6 | \renewcommand{\cleardoublepage}{} 7 | \renewcommand{\clearpage}{} 8 | \rSec0[dcl.decl]{Declarators} 9 | \endgroup 10 | 11 | \setcounter{section}{3} 12 | \setcounter{subsection}{4} 13 | %\rSec2[dcl.fct]{Functions}% 14 | 15 | %NOTES: Fix 16 | %Add paragraph 16. 17 | % 18 | %\begin{quote} 19 | %\setcounter{Paras}{15} 20 | %\pnum 21 | %If the \grammarterm{parameter-declaration-clause} terminates with an ellipsis that is not part of \grammarterm{abstract-declarator}, a function shall not be coroutine (\ref{dcl.fct.def.coroutine}). 22 | %\end{quote} 23 | 24 | \setcounter{section}{3} 25 | \rSec1[dcl.fct.def]{Function definitions} 26 | 27 | \setcounter{subsection}{3} 28 | \rSec2[dcl.fct.def.coroutine]{Coroutines} 29 | 30 | Add this subclause to \ref{dcl.fct.def}. 31 | 32 | %\rSec3[coroutine.definitions]{Definitions} 33 | \begin{quote} 34 | \pnum 35 | A function is a \defn{coroutine} if it contains a \grammarterm{coroutine-return-statement} (\ref{stmt.return.coroutine}), an \grammarterm{await-expression} (\ref{expr.await}), a \grammarterm{yield-expression} (\ref{expr.yield}), or a range-based \tcode{for} (\ref{stmt.ranged}) with \tcode{co_await}. 36 | The \grammarterm{parameter-declaration-clause} of the coroutine shall not terminate with an ellipsis that is not part of a \grammarterm{parameter-declaration}. 37 | 38 | %Every coroutine 39 | %also has an implicit initial and final suspend-resume point as described later in this section. 40 | 41 | %NOTES: add wording for 42 | 43 | %\pnum 44 | %\enternote 45 | %From the perspective of the caller, a coroutine is just a function with that particular signature. The fact that a function is implemented as a coroutine is unobservable by the caller. 46 | %\exitnote 47 | 48 | \pnum 49 | \enterexample 50 | \begin{codeblock} 51 | task f(); 52 | 53 | task g1() { 54 | int i = co_await f(); 55 | std::cout << "f() => " << i << std::endl; 56 | } 57 | 58 | template 59 | task g2(Args&&...) { // OK: ellipsis is a pack expansion 60 | int i = co_await f(); 61 | std::cout << "f() => " << i << std::endl; 62 | } 63 | 64 | task g3(int a, ...) { // error: variable parameter list not allowed 65 | int i = co_await f(); 66 | std::cout << "f() => " << i << std::endl; 67 | } 68 | 69 | \end{codeblock} 70 | \exitexample 71 | % 72 | %\enterexample 73 | %\begin{codeblock} 74 | % // coroutine hello world 75 | % generator hello_fn() { 76 | % for (auto ch: "Hello, world") co_yield ch; 77 | % } 78 | % 79 | % int main() { 80 | % // coroutine as a lambda 81 | % auto hello_lambda = []()->generator { 82 | % for (auto ch: "Hello, world") co_yield ch; }; 83 | % 84 | % for (auto ch : hello_lambda()) std::cout << ch; 85 | % for (auto ch : hello_fn()) std::cout << ch; 86 | % } 87 | %\end{codeblock} 88 | %\exitexample 89 | 90 | %\pnum 91 | %A coroutine needs a set of related types and functions 92 | %to complete the definition of its semantics. 93 | %These types and functions are provided as a set of member types or typedefs 94 | %and member functions in the specializations of class template 95 | %\tcode{std::experimental::coroutine_traits} (\ref{coroutine.traits}). 96 | 97 | \pnum 98 | For a coroutine \textit{f} that is a non-static member function, let $P_1$ denote the type of the implicit object parameter (\cxxref{over.match.funcs}) and $P_2$ ... $P_n$ be the types of the function parameters; otherwise let $P_1$ ... $P_n$ be the types of the function parameters. Let $p_1$ ... $p_n$ be lvalues denoting those objects. 99 | Let \textit{R} be the return type and \textit{F} be the \grammarterm{function-body} 100 | %\footnote{ 101 | %Due to requirement of having suspend-resume points, 102 | %\grammarterm{function-body} is either a 103 | %\grammarterm{compound-statement} or 104 | %\grammarterm{function-try-block}. 105 | %} 106 | of \textit{f}, \textit{T} be the type \tcode{std::experimental::coroutine_traits<$R$,$P_1$,...,$P_n$>}, and \textit{P} be the class type denoted by \textit{T}\tcode{::promise_type}. 107 | %If \textit{T}\tcode{::promise_type} does not refer to a type the program is ill-formed. Type \textit{P} is the \term{promise type} of the coroutine. 108 | Then, the coroutine behaves as if its body were: 109 | \begin{codeblock} 110 | { 111 | @\textit{P }$p$ \textit{promise-constructor-arguments}@; 112 | co_await @$p$@.initial_suspend(); // initial suspend point 113 | try { @\textit{F}@ } catch(...) { @\textit{p}@.unhandled_exception(); } 114 | @\textit{final_suspend}@: 115 | co_await @$p$@.final_suspend(); // final suspend point 116 | } 117 | \end{codeblock} 118 | where an object denoted as \textit{p} is the \defn{promise object} of 119 | the coroutine and its type $P$ is the \defn{promise type} 120 | of the coroutine, 121 | and \textit{promise-constructor-arguments} is determined as follows: 122 | overload resolution is performed on a promise constructor call created by 123 | assembling an argument list with lvalues $p_1$ ... $p_n$. If a viable 124 | constructor is found (\cxxref{over.match.viable}), then 125 | \textit{promise-constructor-arguments} is 126 | \tcode{(}$p_1$,...,$p_n$\tcode{)}, otherwise 127 | \textit{promise-constructor-arguments} is empty. 128 | %,except that any exception thrown after the initial suspend point and 129 | %before the flow of execution reaches \textit{F} also results in entering 130 | %the \grammarterm{handler} of the \grammarterm{try-block}. 131 | 132 | \pnum 133 | The \grammarterm{unqualified-id}{s} 134 | \tcode{return_void} and \tcode{return_value} are looked up in the scope of class $P$. 135 | If both are found, the program is ill-formed. 136 | If the \grammarterm{unqualified-id} \tcode{return_void} is found, flowing off the end of a coroutine is equivalent to a \tcode{co_return} with no operand. Otherwise, flowing off the end of a coroutine results in undefined behavior. 137 | 138 | %\pnum 139 | %An execution of a coroutine is suspended when it reaches a suspend-resume-point. 140 | %A suspension of a coroutine returns control to the current 141 | %caller of the coroutine. For the first return of control from the coroutine, the return value is obtained via 142 | %expression \tcode{$p$.get_return_object()}. 143 | 144 | %\pnum 145 | %When a coroutine returns to its caller, the return value is produced as if by the statement \mbox{\tcode{return}{ }$gro$\tcode{;}} 146 | 147 | \pnum 148 | When a coroutine returns to its caller, the return value is produced by a call to \linebreak 149 | \mbox{\tcode{$p$.get_return_object()}}. A call to a \tcode{get_return_object} is sequenced before the call to \linebreak 150 | \mbox{\tcode{initial_suspend}} and is invoked at most once. 151 | 152 | 153 | %\enternote 154 | %For subsequent suspends, if any, the coroutine 155 | %is invoked via resumption member functions of 156 | %%NOTE massage 157 | %\tcode{std::experimental::coroutine_handle} (\ref{coroutine.handle}) and no return value is expected. 158 | %\exitnote 159 | 160 | \pnum 161 | A suspended coroutine can be resumed 162 | to continue execution by invoking 163 | a resumption member function (\ref{coroutine.handle.resumption}) of an object of type \tcode{coroutine_handle<$P$>} 164 | associated with this instance of the coroutine. The function that invoked a resumption member function is called \term{resumer}. Invoking a resumption member function for a coroutine that is not suspended results in undefined behavior. 165 | 166 | \pnum 167 | An implementation may need to allocate additional storage for a coroutine. 168 | This storage is known as the \defn{coroutine state} and is obtained by calling a non-array allocation function~(\cxxref{basic.stc.dynamic.allocation}). 169 | The allocation function's name is looked up in the scope of $P$. If this lookup fails, the allocation function's name is looked up in the global scope. If the lookup finds an allocation function in the scope of $P$, 170 | %\removed{and that function takes exactly one parameter, it will be used; otherwise, all parameters of the coroutine are passed to the allocation function after the size parameter in order.} 171 | overload resolution is performed on a function call created by assembling an argument list. The first argument is the amount of space requested, and has type \tcode{std::size_t}. The lvalues $p_1$ ... $p_n$ are the succeeding arguments. If no viable function is found (\cxxref{over.match.viable}), overload resolution is performed again on a function call created by passing just the amount of space required as an argument of type \tcode{std::size_t}. 172 | %\enternote 173 | %An allocation function template shall have two or more function parameters. 174 | %A template instance is never considered to be an allocation function with exactly one parameter, regardless of its signature. 175 | %\exitnote 176 | 177 | 178 | \pnum 179 | The \grammarterm{unqualified-id} \tcode{get_return_object_on_allocation_failure} is looked up in the scope of class \textit{P} 180 | by class member access lookup (\cxxref{basic.lookup.classref}). If a declaration is found, then the result of a call to an allocation function used to obtain storage for the coroutine state is assumed to return 181 | \tcode{nullptr} if it fails to obtain storage, and if a global allocation function is selected, the \tcode{::operator new(size_t, nothrow_t)} form shall be used. 182 | %is passed to an allocaiton. 183 | If an allocation function returns \tcode{nullptr}, the coroutine returns control to the caller of the coroutine and the return value is obtained by a call to $P$\tcode{::get_return_object_on_allocation_failure()}. 184 | The allocation function used in this case must have a non-throwing \grammarterm{noexcept-specification}. 185 | 186 | \enterexample 187 | \begin{codeblock} 188 | #include 189 | #include 190 | 191 | // ::operator new(size_t, nothrow_t) will be used if allocation is needed 192 | struct generator { 193 | struct promise_type; 194 | using handle = std::experimental::coroutine_handle; 195 | struct promise_type { 196 | int current_value; 197 | static auto get_return_object_on_allocation_failure() { return generator{nullptr}; } 198 | auto get_return_object() { return generator{handle::from_promise(*this)}; } 199 | auto initial_suspend() { return std::experimental::suspend_always{}; } 200 | auto final_suspend() { return std::experimental::suspend_always{}; } 201 | void unhandled_exception() { std::terminate(); } 202 | void return_void() {} 203 | auto yield_value(int value) { 204 | current_value = value; 205 | return std::experimental::suspend_always{}; 206 | } 207 | }; 208 | bool move_next() { return coro ? (coro.resume(), !coro.done()) : false; } 209 | int current_value() { return coro.promise().current_value; } 210 | generator(generator const&) = delete; 211 | generator(generator && rhs) : coro(rhs.coro) { rhs.coro = nullptr; } 212 | ~generator() { if (coro) coro.destroy(); } 213 | private: 214 | generator(handle h) : coro(h) {} 215 | handle coro; 216 | }; 217 | generator f() { co_yield 1; co_yield 2; } 218 | int main() { 219 | auto g = f(); 220 | while (g.move_next()) std::cout << g.current_value() << std::endl; 221 | } 222 | \end{codeblock} 223 | \exitexample 224 | 225 | \pnum 226 | The coroutine state is destroyed when 227 | control flows off the end of the coroutine or 228 | the \tcode{destroy} member function (\ref{coroutine.handle.resumption}) of an object of type \tcode{std::experimental::coroutine_handle<\textit{P}}> associated with this coroutine is invoked. In the latter case objects with automatic storage duration that are in scope 229 | at the suspend point are destroyed in the reverse order of the construction. The storage for the coroutine state is released by calling a non-array deallocation 230 | function~(\cxxref{basic.stc.dynamic.deallocation}). If \tcode{destroy} is called for a coroutine that is not suspended, the program has undefined behavior. 231 | 232 | \pnum 233 | The deallocation function's name is looked up in the scope of $P$. If this lookup fails, the deallocation function's name is looked up in the global scope. If deallocation function lookup finds both a usual deallocation function with only a pointer parameter and a usual deallocation function with both a pointer parameter and a size parameter, then the selected deallocation function shall be the one with two parameters. Otherwise, the selected deallocation function shall be the function with one parameter. If no usual deallocation function is found, the program is ill-formed. 234 | The selected deallocation function shall be called with the address of the block of storage to be reclaimed as its first argument. If a deallocation function with a parameter of type \tcode{std::size_t} is used, the size of the block is passed as the corresponding argument. 235 | 236 | %introduce metavariable instead of talking about 237 | %coroutine_handle<> 238 | 239 | \pnum 240 | When a coroutine is invoked, a copy is created for each coroutine parameter. Each such copy is an object with automatic storage duration that is direct-initialized from an lvalue referring to the corresponding parameter if the parameter is an lvalue reference, and from an xvalue referring to it otherwise. A reference to a parameter in the function-body of the coroutine and in the call to the coroutine promise constructor is replaced by a reference to its copy. 241 | The initialization and destruction of each parameter copy occurs in the context of the called coroutine. 242 | Initializations of parameter copies are sequenced before the call to the coroutine promise constructor and indeterminately sequenced with respect to each other. 243 | The lifetime of parameter copies ends immediately after the lifetime of the coroutine promise object ends. 244 | \enternote 245 | If a coroutine has a parameter passed by reference, resuming the coroutine after the lifetime of the entity referred to by that parameter has ended is likely to result in undefined behavior. 246 | \exitnote 247 | %\pnum 248 | %An invocation of a coroutine may incur an extra copy/move operation for the parameters. 249 | %%These copies are defined in the same scope as a \term{promise object}. 250 | %A references to a parameter in the \grammarterm{function-body} 251 | %of the coroutine is replaced by a 252 | %reference to the copy of the parameter. 253 | %If a parameter copy/move is required, class object moves are performed according to the rules described in \cxxref{class.copy}/28 [class.copy]. 254 | % 255 | %\enternote 256 | %This transformation could look as follows: 257 | % 258 | %\begin{codeblock} 259 | % auto foo(A a, B& b, C&& c, D* d) { 260 | % A a' = move(a); 261 | % B& b' = b; 262 | % C&& c' = move(c); 263 | % D* d' = d; 264 | % yield 5; // lifetime of parameters end as per 5.2.2/[expr.call] 265 | % ...// any parameter mentioned here will refer to its copy 266 | % } 267 | %\end{codeblock} 268 | %\exitnote 269 | 270 | %\ednote{This is what we currently say about parameters} 271 | 272 | %NOTE: massage 273 | %\pnum 274 | %The region of a coroutine state storing parameters to the coroutine is copy-initialized with the parameter values. 275 | %\enternote 276 | %This copy may be elided (\cxxref{class.copy}). 277 | %\exitnote 278 | 279 | %NOTE: say something that we need to check 280 | %Will be moved to coroutine state and can elide the move. 281 | %syntactic constraint will be checked. 282 | 283 | %NOTE: eventual-return type not defined anywhere 284 | 285 | %\pnum 286 | %If during the coroutine state initialization, a call to \tcode{get_return_object}, or a promise object construction throws 287 | %an exception, objects with automatic storage duration (\cxxref{basic.stc.auto}) that have been 288 | %constructed are destroyed in the reverse order of their construction, 289 | %any memory dynamically allocated 290 | %for the coroutine state is freed and the search for a handler starts in the scope of the calling function. 291 | 292 | %\pnum 293 | %\enterexample 294 | %\begin{codeblock} 295 | % // using a stateful allocator 296 | % class Arena; 297 | % struct my_coroutine { 298 | % struct promise_type { 299 | % ... 300 | % template 301 | % void* operator new(std::size_t size, Arena& pool, TheRest const&...) { 302 | % return pool.allocate(size); 303 | % } 304 | % void operator delete(void* p, std::size_t size) { 305 | % // reference to a pool is not available 306 | % // to the delete operator and should be stored 307 | % // by the allocator as a part of the allocation 308 | % Arena::deallocate(p, size); 309 | % } 310 | % }; 311 | % }; 312 | % 313 | % my_coroutine f(Arena& a) { 314 | % // will call my_coroutine::promise_type::operator new(, a) 315 | % // to obtain storage for the coroutine state 316 | % co_yield 1; 317 | % } 318 | % 319 | % int main() { 320 | % Arena memPool; 321 | % for (int i = 0; i < 1'000'000; ++i) f(memPool); 322 | % }; 323 | %\end{codeblock} 324 | %\exitexample 325 | \end{quote} -------------------------------------------------------------------------------- /Coroutines/expressions.tex: -------------------------------------------------------------------------------- 1 | 2 | 3 | \rSec0[expr]{Expressions} 4 | 5 | \setcounter{section}{2} 6 | \rSec1[expr.unary]{Unary expressions} 7 | 8 | %In this section add the \tcode{co_await} \grammarterm{cast-expression} 9 | %to the rule for \grammarterm{unary-expression}. 10 | 11 | Add \grammarterm{await-expression} to the grammar production \grammarterm{unary-expression}: 12 | 13 | \begin{bnf} 14 | \nontermdef{unary-expression}\br 15 | postfix-expression\br 16 | \terminal{++} cast-expression\br 17 | \terminal{-{-}} cast-expression\br 18 | \added{await-expression}\br 19 | unary-operator cast-expression\br 20 | \terminal{sizeof} unary-expression\br 21 | \terminal{sizeof (} type-id \terminal{)}\br 22 | \terminal{sizeof ...} \terminal{(} identifier \terminal{)}\br 23 | \terminal{alignof (} type-id \terminal{)}\br 24 | noexcept-expression\br 25 | new-expression\br 26 | delete-expression\br 27 | \end{bnf} 28 | 29 | %\setcounter{subsection}{6} 30 | %\rSec2[expr.unary.noexcept]{\tcode{noexcept} operator} 31 | % 32 | %%NOTES: noexcept 33 | %% the resul 34 | % 35 | %% if in a potentially-evaluated context would contain the expression 36 | %Add a new paragraph after paragraph 3. 37 | % 38 | %\begin{quote} 39 | %\setcounter{Paras}{3} 40 | %\pnum 41 | %If in a potentially-evaluated context the \textit{expression} would contain a potentially-evaluated \grammarterm{await-expression}, the program is ill-formed. 42 | %\end{quote} 43 | 44 | \setcounter{subsection}{7} 45 | \rSec2[expr.await]{Await} 46 | 47 | Add this subclause to \ref{expr.unary}. 48 | 49 | %NOTES: add quote 50 | \begin{quote} 51 | \pnum 52 | The \tcode{co_await} expression is used to suspend evaluation of a 53 | %the enclosing 54 | coroutine (\ref{dcl.fct.def.coroutine}) while awaiting completion of the computation represented by the operand expression. 55 | 56 | \begin{bnf} 57 | \nontermdef{await-expression}\br 58 | \terminal{co_await} cast-expression 59 | \end{bnf} 60 | 61 | \pnum 62 | An \grammarterm{await-expression} shall appear only in a potentially-evaluated expression within the \grammarterm{compound-statement} of a \grammarterm{function-body} 63 | outside of a \grammarterm{handler} (Clause \cxxref{except}). In a \grammarterm{declaration-statement} or in the \grammarterm{simple-declaration} (if any) of a \grammarterm{for-init-statement}, an \grammarterm{await-expression} shall appear only in an \grammarterm{initializer} of that \grammarterm{declaration-statement} or \grammarterm{simple-declaration}. 64 | An \grammarterm{await-expression} shall not appear in a default argument (\cxxref{dcl.fct.default}). A context within a function where an \grammarterm{await-expression} can appear is called a \term{suspension context} of the function. 65 | 66 | \pnum 67 | Evaluation of an \grammarterm{await-expression} involves the following auxiliary types, expressions, and objects: 68 | 69 | \begin{itemize} 70 | 71 | % \item If the \grammarterm{cast-expression} is a prvalue, $a$ is a temporary object copy-initialized from the \grammarterm{cast-expression}, otherwise $a$ is an lvalue referring to the result of evaluating the \grammarterm{cast-expression}. 72 | 73 | \item $p$ is an lvalue naming the promise object (\ref{def.fct.def.coroutine}) of the enclosing coroutine and $P$ is the type of that object. 74 | 75 | \item $a$ is the \grammarterm{cast-expression} if 76 | the \grammarterm{await-expression} was implicitly produced by a \grammarterm{yield-expression} (\ref{expr.yield}), an initial suspend point, or a final suspend point (\ref{dcl.fct.def.coroutine}). 77 | Otherwise, the \grammarterm{unqualified-id} \tcode{await_transform} is looked up within the scope of \tcode{$P$} by class member access lookup (\cxxref{basic.lookup.classref}), and if this lookup finds at least one declaration, then $a$ is \linebreak\mbox{\tcode{$p$.await_transform(\grammarterm{cast-expression});}} otherwise, $a$ is the \grammarterm{cast-expression}. 78 | 79 | % \item The \grammarterm{unqualified-id} \tcode{await_transform} is looked up within the scope of \tcode{$P$} by class member access lookup (\cxxref{basic.lookup.classref}), and if this lookup finds at least one declaration, then $a$ is \tcode{$p$.await_transform(\grammarterm{cast-expression});} otherwise, $a$ is \grammarterm{cast-expression}. $a$ is always \grammarterm{cast-expression} for implicit \grammarterm{await-expression}s produced by \grammarterm{yield-expression} (\ref{expr.yield}), or initial and final suspend points (\ref{dcl.fct.def.coroutine}). 80 | % Let $A$ be the type of $a$. 81 | 82 | \item 83 | $o$ is determined by enumerating the applicable \tcode{operator co_await} functions for an argument $a$ (\cxxref{over.match.oper}), and choosing the best one through overload resolution (\cxxref{over.match}). If overload resolution is ambiguous, the program is ill-formed. If no viable functions are found, $o$ is $a$. Otherwise, $o$ is a call to the selected function. 84 | 85 | % 86 | % \item If $A$ is a class type, the \grammarterm{unqualified-id}{s} 87 | % \tcode{await_ready}, \tcode{await_suspend} and \tcode{await_resume} are looked up in the scope of class $A$ by class member access lookup (\cxxref{basic.lookup.classref}) and if this lookup finds at least one declaration, then $o$ is $a$; otherwise, $o$ is 88 | % the result of the invocation of the unary \tcode{co_await} operator function applied to expression $a$ (\cxxref{over.match.oper}). 89 | % \item If the qualified lookup of \tcode{$A$::operator co_await} finds at least one declaration, $o$ is \break \tcode{$a$.operator co_await()}; otherwise, if the \grammarterm{unqualified-id}{s} 90 | % \tcode{await_ready}, \tcode{await_suspend} and \tcode{await_resume} are looked up in the scope of class $A$ as if by class member access lookup (\cxxref{basic.lookup.classref}) and if this lookup finds at least one declaration, then, $o$ is $a$; otherwise, $o$ is \tcode{operator co_await($a$)}. 91 | \item $e$ is a temporary object copy-initialized from $o$ if $o$ is a prvalue; otherwise $e$ is an lvalue referring to the result of evaluating $o$. 92 | 93 | % \item If the \grammarterm{await-expression} is potentially-evaluated and lookup for the unqualified-id \tcode{await_transform} within the scope of \tcode{decltype($p$)} as if by class member access lookup (\cxxref{basic.lookup.classref}) finds at least one declaration, then $e$ is \tcode{$p$.await_transform(a);} otherwise, $e$ is $a$. 94 | \item $h$ is an object of type \tcode{std::experimental::coroutine_handle<$P$>} referring to the enclosing coroutine. 95 | \item \textit{await-ready} is the expression \tcode{$e$.await_ready()}, contextually converted to \tcode{bool}. 96 | \item \textit{await-suspend} is the expression \tcode{$e$.await_suspend($h$)}, which shall be a prvalue of type \tcode{void}, \tcode{bool}, or \tcode{std::experimental::coroutine_handle<}$Z$\tcode{>} for some type $Z$. 97 | \item \textit{await-resume} is the expression \tcode{$e$.await_resume()}. 98 | \end{itemize} 99 | %In an unevaluated operand, only the expressions $a$, $e$, and \textit{await-resume} are required to be valid, and the \grammarterm{await-expression} is equivalent to the \textit{await-resume} expression. 100 | 101 | \pnum The \grammarterm{await-expression} has the same type and value category as the \textit{await-resume} expression. 102 | 103 | \pnum The \grammarterm{await-expression} evaluates the \textit{await-ready} expression, then: 104 | \begin{itemize} 105 | \item If the result is \tcode{false}, the coroutine is considered suspended. Then, the \textit{await-suspend} expression is evaluated. 106 | If that expression has type \tcode{std::experimental::coroutine_handle<}$Z$\tcode{>} and evaluates to a value $s$, the coroutine referred to by $s$ is resumed as if by a call $s$\tcode{.resume()}. \enternote Any number of coroutines may be successively resumed in this fashion, eventually returning control flow to the current coroutine caller or resumer (\ref{dcl.fct.def.coroutine}). \exitnote 107 | If that expression has 108 | type \tcode{bool} and evaluates to \tcode{false}, the coroutine is resumed. 109 | If that expression exits via an exception, the exception is caught, the coroutine is resumed, and the exception is immediately re-thrown (\cxxref{except.throw}). Otherwise, control flow returns to the current coroutine caller or resumer (\ref{dcl.fct.def.coroutine}) without exiting any scopes (\ref{stmt.jump}). 110 | \item If the result is \tcode{true}, or when the coroutine is resumed, the \textit{await-resume} expression is evaluated, and its result is the result of the \grammarterm{await-expression}. 111 | 112 | \end{itemize} 113 | 114 | \pnum 115 | %\enternote 116 | %An \grammarterm{await-expression} may appear as an unevaluated operand (Clause \ref{expr}). 117 | \enterexample 118 | \begin{codeblock} 119 | template 120 | struct my_future { 121 | ... 122 | bool await_ready(); 123 | void await_suspend(std::experimental::coroutine_handle<>); 124 | T await_resume(); 125 | }; 126 | 127 | template 128 | auto operator co_await(std::chrono::duration d) { 129 | struct awaiter { 130 | std::chrono::system_clock::duration duration; 131 | ... 132 | awaiter(std::chrono::system_clock::duration d) : duration(d){} 133 | bool await_ready() const { return duration.count() <= 0; } 134 | void await_resume() {} 135 | void await_suspend(std::experimental::coroutine_handle<> h){...} 136 | }; 137 | return awaiter{d}; 138 | } 139 | 140 | using namespace std::chrono; 141 | 142 | my_future h(); 143 | 144 | my_future g() { 145 | std::cout << "just about go to sleep...\n"; 146 | co_await 10ms; 147 | std::cout << "resumed\n"; 148 | co_await h(); 149 | } 150 | 151 | auto f(int x = co_await h()); // error: await-expression outside of function suspension context 152 | int a[] = { co_await h() }; // error: await-expression outside of function suspension context 153 | 154 | \end{codeblock} 155 | \exitexample% 156 | %\exitnote 157 | 158 | \end{quote} 159 | %, i.e a coroutine shall have the \tcode{return_value} or \tcode{return_void} member 160 | %functions defined in its \term{promise type} 161 | % 162 | %\rSec2[expr.await.old]{Old version of Coawait for wording comparison} 163 | % 164 | %\pnum 165 | %A \tcode{await} expression of the form 166 | % 167 | %\begin{ncbnf} 168 | % \terminal{co_await} cast-expression 169 | %\end{ncbnf} 170 | %is equivalent to \footnote{if it were possible to write 171 | %an expression in terms of a block, where return from the 172 | %block becomes the result of the expression} 173 | % 174 | %\begin{codeblock} 175 | %{ 176 | % auto && __expr = @\grammarterm{cast-expression}@; 177 | % if ( !@\textit{await-ready-expr}@ ) { 178 | % @\textit{await-suspend-expr}@; 179 | % @\textit{suspend-resume point}@ 180 | % } 181 | % return await-resume-expr; 182 | %} 183 | %\end{codeblock} 184 | % 185 | %otherwise, the await expression is equivalent 186 | % 187 | %%NOTE: 188 | %%The type, value category and value of an await expression are those of \texit{await-resume-expr}. 189 | % 190 | %%NOTE: try rewriting that so that definitions come first 191 | % 192 | %%NOTE: start with if 193 | % 194 | %% otherwise, the await expression is equivalent 195 | % 196 | %%drop the footnote 197 | % 198 | %% NOTE: add that await expression cannot be a constexpr to the list of things that cannot be a constexpr 199 | % 200 | %% new wording 201 | %%await cast-expression executes as if "block" and return of that an await expression is. 202 | % 203 | % 204 | %if the type of \textit{await-suspend-expr} is \tcode{void}, otherwise it is equivalent to 205 | % 206 | %\begin{codeblock} 207 | %{ 208 | % auto && __expr = @\grammarterm{cast-expression}@; 209 | % if ( !await-ready-expr && await-suspend-expr ) { 210 | % @\textit{suspend-resume-point}@ 211 | % } 212 | % return await-resume-expr; 213 | %} 214 | %\end{codeblock} 215 | % 216 | %where \tcode{__expr} is a variable defined for 217 | %exposition only, and \tcode{_ExprT} is the type of the 218 | %\grammarterm{cast-expression}, and \tcode{_PromiseT} is the 219 | %promise type of the enclosing coroutine, 220 | %and \tcode{_CoroutineHandle} 221 | %is an object of the type \tcode{std::experimental::coroutine_handle<_PromiseT>} (\ref{coroutine.handle}) corresponding to the enclosing function, 222 | %%NOTES add reference to promise 223 | %and \textit{await-ready-expr}, \textit{await-suspend-expr}, and \textit{await-expr} are 224 | %determined as follows: 225 | % 226 | %% _ExprT == T 227 | %% _CoroutineHandle == c 228 | % 229 | %\begin{itemize} 230 | % \item if the type of the \textit{cast-expression} is a class type, the \grammarterm{unqualified-id}{s} 231 | % \tcode{await_ready}, \tcode{await_suspend}, and \tcode{await_resume} are 232 | % looked up in the scope of that class 233 | % as if by class member access lookup~(\cxxref{basic.lookup.classref}), and if it finds at least one declaration, 234 | % \textit{await-ready}, \textit{await-suspend}, and \textit{await-resume} are 235 | % \tcode{__expr.await_ready()}, \tcode{__expr.await_suspend(_CoroutineHandle)} and \tcode{__expr.await_resume()}, 236 | % respectively; 237 | % 238 | % \item otherwise, \textit{await-ready}, \textit{await-suspend} and \textit{await-resume} are 239 | % \tcode{await_ready(__expr)}, \tcode{await_suspend(__expr, _CoroutineHandle)}, and \tcode{await_resume(__expr)} 240 | % respectively, where 241 | % \textit{await-ready}, \textit{await-suspend}, and \textit{await-resume} are 242 | % looked up in the associated namespaces~(\cxxref{basic.lookup.argdep}). 243 | % \enternote Ordinary unqualified lookup~(\cxxref{basic.lookup.unqual}) is not 244 | % performed. \exitnote 245 | %\end{itemize} 246 | % 247 | %%\enterexample 248 | %%\begin{codeblock} 249 | %% int result = await async([]{return 5;}); 250 | %%\end{codeblock} 251 | %%\exitexample% 252 | 253 | \setcounter{section}{17} 254 | \rSec1[expr.ass]{Assignment and compound assignment operators}% 255 | 256 | %In paragraph 1, 257 | Add \grammarterm{yield-expression} to the grammar production \grammarterm{assignment-expression}. 258 | 259 | \begin{quote} 260 | \begin{bnf} 261 | \nontermdef{assignment-expression}\br 262 | conditional-expression\br 263 | logical-or-expression assignment-operator initializer-clause\br 264 | throw-expression \br 265 | \added{yield-expression} 266 | \end{bnf} 267 | \end{quote} 268 | 269 | \setcounter{section}{19} 270 | \rSec1[expr.const]{Constant expressions}% 271 | 272 | Add bullets prohibiting \grammarterm{await-expression} and \grammarterm{yield-expression} to paragraph 2. 273 | 274 | \begin{quote} 275 | \begin{itemize} 276 | \item 277 | \added{an \grammarterm{await-expression} (\ref{expr.await});} 278 | \item 279 | \added{a \grammarterm{yield-expression} (\ref{expr.yield});} 280 | \end{itemize} 281 | \end{quote} 282 | 283 | \setcounter{section}{20} 284 | \rSec1[expr.yield]{Yield}% 285 | 286 | Add a new subclause to Clause \ref{expr}. 287 | 288 | \begin{quote} 289 | \begin{bnf} 290 | \nontermdef{yield-expression}\br 291 | \terminal{co_yield} assignment-expression\br 292 | \terminal{co_yield} braced-init-list 293 | \end{bnf} 294 | 295 | \pnum 296 | A \grammarterm{yield-expression} shall appear only within a suspension context of a function (\ref{expr.await}). 297 | Let \textit{e} be the operand of the \grammarterm{yield-expression} and \textit{p} be an lvalue naming the promise object of the enclosing coroutine (\ref{dcl.fct.def.coroutine}), then the \grammarterm{yield-expression} is equivalent to the expression \tcode{co_await} \textit{p}\tcode{.yield_value}(\textit{e}). 298 | 299 | % If coroutine promise does not define a function \tcode{yield_value}, the program is ill-formed. 300 | % An implicit \grammarterm{await-expression} introduced by this evaluation is not considered an \grammarterm{await-expression} for the purpose of type deduction (\ref{dcl.spec.auto}). 301 | 302 | %\pnum 303 | \enterexample 304 | \begin{codeblock} 305 | template 306 | struct my_generator { 307 | struct promise_type { 308 | T current_value; 309 | ... 310 | auto yield_value(T v) { 311 | current_value = std::move(v); 312 | return std::experimental::suspend_always{}; 313 | } 314 | }; 315 | struct iterator { ... }; 316 | iterator begin(); 317 | iterator end(); 318 | }; 319 | 320 | my_generator> g1() { 321 | for (int i = i; i < 10; ++i) co_yield {i,i}; 322 | } 323 | my_generator> g2() { 324 | for (int i = i; i < 10; ++i) co_yield make_pair(i,i); 325 | } 326 | 327 | auto f(int x = co_yield 5); // error: yield-expression outside of function suspension context 328 | int a[] = { co_yield 1 }; // error: yield-expression outside of function suspension context 329 | 330 | int main() { 331 | auto r1 = g1(); 332 | auto r2 = g2(); 333 | assert(std::equal(r1.begin(), r1.end(), r2.begin(), r2.end())); 334 | } 335 | \end{codeblock} 336 | 337 | \exitexample 338 | % 339 | %\pnum 340 | %All restrictions on where an \textit{await-expression} can appear apply to \textit{yield-expression}{}s. 341 | % 342 | 343 | %\pnum 344 | %\enterexample 345 | %\begin{codeblock} 346 | % auto f(int x = yield 5); // ill-formed 347 | % int a[] = { yield 1 }; // ill-formed 348 | %\end{codeblock} 349 | %\exitexample 350 | 351 | 352 | \end{quote} 353 | 354 | -------------------------------------------------------------------------------- /Coroutines/foreword.tex: -------------------------------------------------------------------------------- 1 | \addcontentsline{toc}{chapter}{Foreword} 2 | \chapter*{Foreword} 3 | ISO (the International Organization for Standardization) and IEC (the International 4 | Electrotechnical Commission) form the specialized system for worldwide standardization. 5 | National bodies that are members of ISO or IEC participate in the development of 6 | International Standards through technical committees established by the respective 7 | organization to deal with particular fields of technical activity. ISO and IEC 8 | technical committees collaborate in fields of mutual interest. Other international 9 | organizations, governmental and non-governmental, in liaison with ISO and IEC, 10 | also take part in the work. In the field of information technology, ISO and IEC 11 | have established a joint technical committee, ISO/IEC JTC 1. 12 | 13 | The procedures used to develop this document and those intended for its further 14 | maintenance are described in the ISO/IEC Directives, Part 1. In particular the 15 | different approval criteria needed for the different types of document should be 16 | noted. This document was drafted in accordance with the editorial rules of the 17 | ISO/IEC Directives, Part 2 (see \url{www.iso.org/directives}). 18 | 19 | Attention is drawn to the possibility that some of the elements of this document 20 | may be the subject of patent rights. ISO and IEC shall not be held responsible 21 | for identifying any or all such patent rights. Details of any patent rights 22 | identified during the development of the document will be in the Introduction 23 | and/or on the ISO list of patent declarations received (see \url{www.iso.org/patents}). 24 | 25 | Any trade name used in this document is information given for the convenience of 26 | users and does not constitute an endorsement. 27 | 28 | For an explanation on the voluntary nature of standards, the meaning of ISO 29 | specific terms and expressions related to conformity assessment, as well as 30 | information about ISO's adherence to the World Trade Organization (WTO) principles 31 | in the Technical Barriers to Trade (TBT) see the following URL: 32 | \url{www.iso.org/iso/foreword.html}. 33 | 34 | This document was prepared by Technical Committee ISO/IEC JTC 1, \emph{Information 35 | technology}, Subcommittee SC 22, \emph{Programming languages, their environments and 36 | system software interfaces}. 37 | -------------------------------------------------------------------------------- /Coroutines/front.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | \input{cover-wd} 3 | %\input{cover-reg} 4 | 5 | %%-------------------------------------------------- 6 | %% The table of contents, list of tables, and list of figures 7 | \markboth{\contentsname}{} 8 | 9 | %%-------------------------------------------------- 10 | %% Make a bit more room for our long page numbers. 11 | \makeatletter 12 | \renewcommand\@pnumwidth{2.5em} 13 | \makeatother 14 | 15 | \begin{KeepFromToc} 16 | \tableofcontents 17 | \end{KeepFromToc} 18 | \setcounter{tocdepth}{5} 19 | \newpage 20 | \begin{KeepFromToc} 21 | \listoftables 22 | \end{KeepFromToc} 23 | %\newpage 24 | %\listoffigures 25 | 26 | %\input{preface} 27 | -------------------------------------------------------------------------------- /Coroutines/intro.tex: -------------------------------------------------------------------------------- 1 | 2 | \rSec0[intro.scope]{Scope} 3 | 4 | \pnum 5 | This document describes extensions to the C++ 6 | Programming Language (Clause \ref{intro.refs}) that 7 | enable definition of coroutines. These extensions include 8 | new syntactic forms and modifications to existing language semantics. 9 | 10 | \pnum 11 | The International Standard, ISO/IEC 14882:2017, provides important context 12 | and specification for this document. This document is 13 | written as a set of changes against that specification. Instructions 14 | to modify or add paragraphs are written as explicit instructions. 15 | Modifications made directly to existing text from the International 16 | Standard use \added{underlining} to represent added text and 17 | \removed{strikethrough} to represent deleted text. 18 | 19 | \begingroup 20 | \renewcommand{\cleardoublepage}{} 21 | \renewcommand{\clearpage}{} 22 | \rSec0[intro.refs]{Normative references} 23 | \endgroup 24 | 25 | \pnum 26 | The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. 27 | 28 | \begin{itemize} 29 | \item ISO/IEC 14882:2017, \doccite{Programming Languages -- \Cpp} 30 | \end{itemize} 31 | 32 | ISO/IEC 14882:2017 is hereafter called the \defn{\Cpp Standard}. 33 | % 34 | Beginning with Clause 5, all clause and subclause numbers, titles, 35 | and symbolic references in [brackets] refer to the corresponding elements of the \Cpp Standard. Clauses 1 through 4 of this document 36 | %are introductory material and 37 | are unrelated to the similarly-numbered clauses and subclauses of the \Cpp Standard. 38 | 39 | % NOTES: N4302 use transaction memory edits to fix this. 40 | 41 | \begingroup 42 | \renewcommand{\cleardoublepage}{} 43 | \renewcommand{\clearpage}{} 44 | \rSec0[intro.defs]{Terms and definitions} 45 | \endgroup 46 | 47 | No terms and definitions are listed in this document. 48 | ISO and IEC maintain terminological databases for use in standardization at the following addresses: 49 | 50 | \begin{itemize} 51 | \item ISO Online browsing platform: available at \url{http://www.iso.org/obp} 52 | \item IEC Electropedia: available at \url{http://www.electropedia.org/} 53 | \end{itemize} 54 | %\pnum 55 | %This revision updates N4499 with changes proposed in papers P0054 and P0070. 56 | 57 | \rSec0[intro]{General} 58 | 59 | %\rSec1[intro.ack]{Acknowledgements} 60 | 61 | %This work is the result of a collaboration of researchers in industry and academia. We wish to thank people who made valuable contributions within and outside these groups, including 62 | %Artur Laksberg, 63 | %Chandler Carruth, 64 | %David Vandevoorde, 65 | %Deon Brewis, 66 | %Eric Fiselier, 67 | %Gabriel Dos Reis, 68 | %Herb Sutter, 69 | %James McNellis, 70 | %Jens Maurer, 71 | %Jonathan Caves, 72 | %Lawrence Crowl, 73 | %Lewis Baker, 74 | %Michael Wong, 75 | %Nick Maliwacki, 76 | %Niklas Gustafsson, 77 | %Pablo Halpern, 78 | %Richard Smith, 79 | %Robert Schumacher, 80 | %Shahms King, 81 | %Slava Kuznetsov, 82 | %Stephan T. Lavavej, 83 | %Tongari J, 84 | %Vladimir Petter, 85 | %and many others not named here who contributed to 86 | %the discussion. 87 | 88 | % 89 | %Add the definitions of ``suspend-resume-point'' and ``coroutine''. 90 | % 91 | %\setcounter{subsection}{26} 92 | %\begin{quote} 93 | %\indexdefn{suspend-resume-point}% 94 | %\definition{suspend-resume-point}{defns.suspend.resume} 95 | %A point in a \grammarterm{function-body} 96 | %where evaluation of a function can be suspended 97 | %with possibility of resuming it later 98 | %via a call to a member function of a 99 | %\tcode{coroutine_handle} object associated with the suspended function. 100 | %\end{quote} 101 | % 102 | %\begin{quote} 103 | % \indexdefn{coroutine}% 104 | % \definition{coroutine}{defns.coroutine.function} 105 | % A function defined with \grammarterm{function-body} that 106 | % contains one or more suspend-resume-points. 107 | %\end{quote} 108 | 109 | %% 110 | %% Implementation compliance 111 | %% 112 | \rSec1[intro.compliance]{Implementation compliance} 113 | 114 | %\pnum 115 | Conformance requirements for this specification shall be the same as those 116 | defined in subclause \cxxref{intro.compliance} of the \Cpp Standard. 117 | \enternote 118 | Conformance is defined 119 | in terms of the behavior of programs. 120 | \exitnote 121 | 122 | %% 123 | %% Feature-testing recommendations 124 | %% 125 | \rSec1[intro.features]{Feature testing} 126 | 127 | An implementation that provides support for this document shall define the feature test macro in Table~\ref{tab:info.features}. 128 | 129 | \begin{floattable}{Feature-test macro}{tab:info.features} 130 | {lll} 131 | \topline 132 | \lhdr{Name} & \chdr{Value} & \rhdr{Header} \\ 133 | \capsep 134 | \tcode{__cpp_coroutines} & \tcode{201806} & \textit{predeclared} \\ 135 | \end{floattable} 136 | 137 | %\rSec1[intro.ack]{Acknowledgments} 138 | % 139 | %\pnum 140 | %The design of this specification is based, in part, on a concept 141 | %specification of the algorithms part of the C++ standard library, known 142 | %as ``The Palo Alto'' report (WG21 N3351), which was developed by a large 143 | %group of experts as a test of the expressive power of the idea of 144 | %concepts. Despite syntactic differences between the notation of the 145 | %Palo Alto report and this document, the report can be seen as a 146 | %large-scale test of the expressiveness of this document. 147 | 148 | \rSec1[intro.execution]{Program execution} 149 | In subclause \cxxref{intro.execution} of the \Cpp Standard modify paragraph 6 to read: 150 | \begin{quote} 151 | \setcounter{Paras}{6} 152 | \pnum 153 | An instance of each object with automatic storage 154 | duration~(\cxxref{basic.stc.auto}) is associated with each entry into its 155 | block. Such an object exists and retains its last-stored value during 156 | the execution of the block and while the block is suspended (by a call 157 | of a function\added{, suspension of a coroutine (\ref{expr.await})}, 158 | or receipt of a signal). 159 | \end{quote} 160 | 161 | %\rSec1[lex]{Lexical conventions} 162 | % 163 | %In subclause \cxxref{lex.key} of the \Cpp Standard 164 | %add the keywords \tcode{co_await}, \tcode{co_yield}, and 165 | %\tcode{co_return} to Table~4 "Keywords". 166 | 167 | 168 | %sdf sad 169 | %\setcounter{chapter}{2} 170 | %\rSec1[basic]{Basic concepts} 171 | 172 | %\setcounter{section}{6} 173 | %\rSec1[basic.start]{Start and termination} 174 | 175 | %\rSec2[basic.start.main]{Main function} 176 | 177 | %In subclause \cxxref{basic.start.main} of the \Cpp Standard 178 | %add underlined text to paragraph 3. 179 | % 180 | %\begin{quote} 181 | % \setcounter{Paras}{2} 182 | % 183 | % \pnum 184 | % The function \tcode{main} shall not be used within 185 | % a program. 186 | % \indextext{\idxcode{main()}!implementation-defined linkage~of}% 187 | % The linkage~(\cxxref{basic.link}) of \tcode{main} is 188 | % \impldef{linkage of \tcode{main}}. A program that defines \tcode{main} as 189 | % deleted or that declares \tcode{main} to be 190 | % \tcode{inline,} \tcode{static}, or \tcode{constexpr} is ill-formed. 191 | % \added{The function \tcode{main} shall not be a coroutine (\ref{dcl.fct.def.coroutine}).} 192 | % The name \tcode{main} is 193 | % not otherwise reserved. \enterexample member functions, classes, and 194 | % enumerations can be called \tcode{main}, as can entities in other 195 | % namespaces. \exitexample 196 | %\end{quote} 197 | 198 | %\rSec1[basic.stc.dynamic]{Dynamic storage duration} 199 | 200 | %\setcounter{section}{7} 201 | %\setcounter{subsection}{4} 202 | %\rSec3[basic.stc.dynamic.allocation]{Allocation functions} 203 | 204 | %In subclause \cxxref{basic.stc.dynamic.allocation} of the \Cpp Standard 205 | %modify paragraph 4 as follows: 206 | % 207 | %\begin{quote} 208 | % \setcounter{Paras}{3} 209 | % \pnum 210 | % A global allocation function is only called as the result of a new 211 | % expression~(\cxxref{expr.new}), \removed{or} called directly using the function call 212 | % syntax~(\cxxref{expr.call}), 213 | % \added{called indirectly to allocate storage for a coroutine frame (\ref{dcl.fct.def.coroutine}),} 214 | % or called indirectly through calls to the 215 | % functions in the \Cpp standard library. \enternote In particular, a 216 | % global allocation function is not called to allocate storage for objects 217 | % with static storage duration~(\cxxref{basic.stc.static}), for objects or references 218 | % with thread storage duration~(\cxxref{basic.stc.thread}), for objects of 219 | % type \tcode{std::type_info}~(\cxxref{expr.typeid}), or for an 220 | % exception object~(\cxxref{except.throw}). 221 | % \exitnote 222 | %\end{quote} 223 | -------------------------------------------------------------------------------- /Coroutines/layout.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | %% layout.tex -- set overall page appearance 3 | 4 | %%-------------------------------------------------- 5 | %% set page size, type block size, type block position 6 | 7 | \setstocksize{11in}{8.5in} 8 | \settrimmedsize{11in}{8.5in}{*} 9 | \setlrmarginsandblock{1in}{1in}{*} 10 | \setulmarginsandblock{1in}{*}{1.618} 11 | 12 | %%-------------------------------------------------- 13 | %% set header and footer positions and sizes 14 | 15 | \setheadfoot{\onelineskip}{2\onelineskip} 16 | \setheaderspaces{*}{2\onelineskip}{*} 17 | 18 | %%-------------------------------------------------- 19 | %% make miscellaneous adjustments, then finish the layout 20 | \setmarginnotes{7pt}{7pt}{0pt} 21 | \checkandfixthelayout 22 | 23 | %%-------------------------------------------------- 24 | %% Paragraph and bullet numbering 25 | 26 | \newcounter{Paras} 27 | \counterwithin{Paras}{chapter} 28 | \counterwithin{Paras}{section} 29 | \counterwithin{Paras}{subsection} 30 | \counterwithin{Paras}{subsubsection} 31 | \counterwithin{Paras}{paragraph} 32 | \counterwithin{Paras}{subparagraph} 33 | 34 | \newcounter{Bullets1}[Paras] 35 | \newcounter{Bullets2}[Bullets1] 36 | \newcounter{Bullets3}[Bullets2] 37 | \newcounter{Bullets4}[Bullets3] 38 | 39 | \makeatletter 40 | \newcommand{\parabullnum}[2]{% 41 | \stepcounter{#1}% 42 | \noindent\makebox[0pt][l]{\makebox[#2][r]{% 43 | \scriptsize\raisebox{.7ex}% 44 | {% 45 | \ifnum \value{Paras}>0 46 | \ifnum \value{Bullets1}>0 (\fi% 47 | \arabic{Paras}% 48 | \ifnum \value{Bullets1}>0 .\arabic{Bullets1}% 49 | \ifnum \value{Bullets2}>0 .\arabic{Bullets2}% 50 | \ifnum \value{Bullets3}>0 .\arabic{Bullets3}% 51 | \fi\fi\fi% 52 | \ifnum \value{Bullets1}>0 )\fi% 53 | \fi% 54 | }% 55 | \hspace{\@totalleftmargin}\quad% 56 | }}} 57 | \makeatother 58 | 59 | \def\pnum{\parabullnum{Paras}{0pt}} 60 | 61 | % Leave more room for section numbers in TOC 62 | \cftsetindents{section}{1.5em}{3.0em} 63 | 64 | % For compatibility only. We no longer need this environment. 65 | \newenvironment{paras}{}{} 66 | -------------------------------------------------------------------------------- /Coroutines/lex.tex: -------------------------------------------------------------------------------- 1 | 2 | \begingroup 3 | \renewcommand{\cleardoublepage}{} 4 | \renewcommand{\clearpage}{} 5 | \rSec0[lex]{Lexical conventions} 6 | \endgroup 7 | 8 | \setcounter{section}{10} 9 | \Sec1[lex.key]{Keywords} 10 | 11 | Add the keywords \tcode{co_await}, \tcode{co_yield}, and 12 | \tcode{co_return} to Table~5 "Keywords". 13 | 14 | -------------------------------------------------------------------------------- /Coroutines/lib-intro.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = D0057.tex 2 | %\setcounter{chapter}{16} 3 | \rSec0[library]{Library introduction} 4 | 5 | \setcounter{section}{5} 6 | \setcounter{subsection}{1} 7 | \setcounter{subsubsection}{2} 8 | %\rSec1[requirements]{Library-wide requirements} 9 | 10 | %\rSec2[using]{Using the library} 11 | 12 | \rSec3[compliance]{Freestanding implementations} 13 | 14 | Add a row to Table~\ref{tab:cpp.headers.freestanding} for coroutine support header \tcode{}. 15 | 16 | 17 | \setcounter{table}{18} 18 | \begin{libsumtab}{\Cpp headers for freestanding implementations}{tab:cpp.headers.freestanding} 19 | & & \tcode{} \\ \rowsep 20 | \cxxref{support.types} & Types & \tcode{} \\ \rowsep 21 | \cxxref{support.limits}& Implementation properties & \tcode{} \tcode{} \tcode{} \\ \rowsep 22 | \cxxref{cstdint} & Integer types & \tcode{} \\ \rowsep 23 | \cxxref{support.start.term}& Start and termination & \tcode{} \\ \rowsep 24 | \cxxref{support.dynamic} & Dynamic memory management & \tcode{} \\ \rowsep 25 | \cxxref{support.rtti} & Type identification & \tcode{} \\ \rowsep 26 | \cxxref{support.exception} & Exception handling & \tcode{} \\ \rowsep 27 | \cxxref{support.initlist} & Initializer lists & \tcode{} \\ \rowsep 28 | \cxxref{support.runtime} & Other runtime support & \tcode{} \tcode{} \tcode{} \\ \rowsep 29 | \added{\ref{support.coroutine}} 30 | & \added{Coroutines support} 31 | & \added{\tcode{}} \\ \rowsep 32 | \cxxref{meta} & Type traits & \tcode{} \\ \rowsep 33 | \cxxref{atomics} & Atomics & \tcode{} \\ 34 | \end{libsumtab} 35 | -------------------------------------------------------------------------------- /Coroutines/macros.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | % Definitions and redefinitions of special commands 3 | 4 | %%-------------------------------------------------- 5 | %% Difference markups 6 | \definecolor{addclr}{rgb}{0,.6,.6} 7 | \definecolor{remclr}{rgb}{1,0,0} 8 | \definecolor{noteclr}{rgb}{0,0,1} 9 | 10 | \renewcommand{\added}[1]{\textcolor{addclr}{\uline{#1}}} 11 | \newcommand{\removed}[1]{\textcolor{remclr}{\sout{#1}}} 12 | \renewcommand{\changed}[2]{\removed{#1}\added{#2}} 13 | 14 | \newcommand{\nbc}[1]{[#1]\ } 15 | \newcommand{\addednb}[2]{\added{\nbc{#1}#2}} 16 | \newcommand{\removednb}[2]{\removed{\nbc{#1}#2}} 17 | \newcommand{\changednb}[3]{\removednb{#1}{#2}\added{#3}} 18 | \newcommand{\remitem}[1]{\item\removed{#1}} 19 | 20 | \newcommand{\ednote}[1]{\textcolor{noteclr}{[Editor's note: #1] }} 21 | % \newcommand{\ednote}[1]{} 22 | 23 | \newenvironment{addedblock} 24 | { 25 | \color{addclr} 26 | } 27 | { 28 | \color{black} 29 | } 30 | \newenvironment{removedblock} 31 | { 32 | \color{remclr} 33 | } 34 | { 35 | \color{black} 36 | } 37 | 38 | %%-------------------------------------------------- 39 | %% Sectioning macros. 40 | % Each section has a depth, an automatically generated section 41 | % number, a name, and a short tag. The depth is an integer in 42 | % the range [0,5]. (If it proves necessary, it wouldn't take much 43 | % programming to raise the limit from 5 to something larger.) 44 | 45 | 46 | % The basic sectioning command. Example: 47 | % \Sec1[intro.scope]{Scope} 48 | % defines a first-level section whose name is "Scope" and whose short 49 | % tag is intro.scope. The square brackets are mandatory. 50 | \def\Sec#1[#2]#3{% 51 | \ifcase#1\let\s=\chapter 52 | \or\let\s=\section 53 | \or\let\s=\subsection 54 | \or\let\s=\subsubsection 55 | \or\let\s=\paragraph 56 | \or\let\s=\subparagraph 57 | \fi% 58 | \s[#3]{#3\hfill[#2]}\label{#2}} 59 | 60 | % A convenience feature (mostly for the convenience of the Project 61 | % Editor, to make it easy to move around large blocks of text): 62 | % the \rSec macro is just like the \Sec macro, except that depths 63 | % relative to a global variable, SectionDepthBase. So, for example, 64 | % if SectionDepthBase is 1, 65 | % \rSec1[temp.arg.type]{Template type arguments} 66 | % is equivalent to 67 | % \Sec2[temp.arg.type]{Template type arguments} 68 | \newcounter{SectionDepthBase} 69 | \newcounter{scratch} 70 | 71 | \def\rSec#1[#2]#3{% 72 | \setcounter{scratch}{#1} 73 | \addtocounter{scratch}{\value{SectionDepthBase}} 74 | \Sec{\arabic{scratch}}[#2]{#3}} 75 | 76 | \newcommand{\synopsis}[1]{\textbf{#1}} 77 | 78 | %%-------------------------------------------------- 79 | % Indexing 80 | 81 | % locations 82 | \newcommand{\indextext}[1]{\index[generalindex]{#1}} 83 | \newcommand{\indexlibrary}[1]{\index[libraryindex]{#1}} 84 | \newcommand{\indexgram}[1]{\index[grammarindex]{#1}} 85 | \newcommand{\indeximpldef}[1]{\index[impldefindex]{#1}} 86 | 87 | \newcommand{\indexdefn}[1]{\indextext{#1}} 88 | \newcommand{\indexgrammar}[1]{\indextext{#1}\indexgram{#1}} 89 | \newcommand{\impldef}[1]{\indeximpldef{#1}implementation-defined} 90 | 91 | % appearance 92 | \newcommand{\idxcode}[1]{#1@\tcode{#1}} 93 | \newcommand{\idxhdr}[1]{#1@\tcode{<#1>}} 94 | \newcommand{\idxgram}[1]{#1@\textit{#1}} 95 | 96 | %%-------------------------------------------------- 97 | % General code style 98 | \newcommand{\CodeStyle}{\ttfamily} 99 | \newcommand{\CodeStylex}[1]{\texttt{#1}} 100 | 101 | % Code and definitions embedded in text. 102 | \newcommand{\tcode}[1]{\CodeStylex{#1}} 103 | \newcommand{\techterm}[1]{\textit{#1}\xspace} 104 | \newcommand{\defnx}[2]{\indexdefn{#2}\textit{#1}\xspace} 105 | \newcommand{\defn}[1]{\defnx{#1}{#1}} 106 | \newcommand{\term}[1]{\textit{#1}\xspace} 107 | \newcommand{\grammarterm}[1]{\textit{#1}\xspace} 108 | \newcommand{\placeholder}[1]{\textit{#1}\xspace} 109 | 110 | %%-------------------------------------------------- 111 | %% allow line break if needed for justification 112 | \newcommand{\brk}{\discretionary{}{}{}} 113 | % especially for scope qualifier 114 | \newcommand{\colcol}{\brk::\brk} 115 | 116 | %%-------------------------------------------------- 117 | %% Macros for funky text 118 | \newcommand{\Rplus}{\protect\hspace{-.1em}\protect\raisebox{.35ex}{\smaller{\smaller\textbf{+}}}} 119 | % \newcommand{\Rplus}{+} 120 | \newcommand{\Cpp}{\mbox{C\Rplus\Rplus}\xspace} 121 | \newcommand{\CppIII}{\Cpp 2003\xspace} 122 | \newcommand{\CppXI}{\Cpp 2011\xspace} 123 | \newcommand{\opt}{{\ensuremath{_\mathit{opt}}}\xspace} 124 | \newcommand{\shl}{<{<}} 125 | \newcommand{\shr}{>{>}} 126 | \newcommand{\dcr}{-{-}} 127 | \newcommand{\exor}{\^{}} 128 | \newcommand{\bigoh}[1]{\ensuremath{\mathscr{O}(#1)}} 129 | \newcommand{\cvvoid}{\textit{cv}{ }\tcode{void}} 130 | \newcommand{\awready}{\textit{e}\tcode{await_ready()}} 131 | \newcommand{\awsuspend}{\textit{e}\tcode{await_resume(\textit{h})}} 132 | \newcommand{\awresume}{\textit{e}{ }\tcode{await_resume()}} 133 | 134 | % Make all tildes a little larger to avoid visual similarity with hyphens. 135 | % FIXME: Remove \tilde in favour of \~. 136 | \renewcommand{\tilde}{\textasciitilde} 137 | \renewcommand{\~}{\textasciitilde} 138 | \let\OldTextAsciiTilde\textasciitilde 139 | \renewcommand{\textasciitilde}{\protect\raisebox{-0.17ex}{\larger\OldTextAsciiTilde}} 140 | 141 | %%-------------------------------------------------- 142 | %% States and operators 143 | \newcommand{\state}[2]{\tcode{#1}\ensuremath{_{#2}}} 144 | \newcommand{\bitand}{\ensuremath{\, \mathsf{bitand} \,}} 145 | \newcommand{\bitor}{\ensuremath{\, \mathsf{bitor} \,}} 146 | \newcommand{\xor}{\ensuremath{\, \mathsf{xor} \,}} 147 | \newcommand{\rightshift}{\ensuremath{\, \mathsf{rshift} \,}} 148 | \newcommand{\leftshift}[1]{\ensuremath{\, \mathsf{lshift}_#1 \,}} 149 | 150 | %% Notes and examples 151 | \newcommand{\EnterBlock}[1]{[\,\textit{#1:}\xspace} 152 | \newcommand{\ExitBlock}[1]{\textit{\,---\,end #1}\,]\xspace} 153 | \newcommand{\enternote}{\EnterBlock{Note}} 154 | \newcommand{\exitnote}{\ExitBlock{note}} 155 | \newcommand{\enterexample}{\EnterBlock{Example}} 156 | \newcommand{\exitexample}{\ExitBlock{example}} 157 | 158 | %% Library function descriptions 159 | \newcommand{\Fundescx}[1]{\textit{#1}\xspace} 160 | \newcommand{\Fundesc}[1]{\Fundescx{#1:}} 161 | \newcommand{\required}{\Fundesc{Required behavior}} 162 | \newcommand{\requires}{\Fundesc{Requires}} 163 | \newcommand{\effects}{\Fundesc{Effects}} 164 | \newcommand{\postconditions}{\Fundesc{Postconditions}} 165 | \newcommand{\postcondition}{\Fundesc{Postcondition}} 166 | \newcommand{\preconditions}{\requires} 167 | \newcommand{\precondition}{\requires} 168 | \newcommand{\returns}{\Fundesc{Returns}} 169 | \newcommand{\throws}{\Fundesc{Throws}} 170 | \newcommand{\default}{\Fundesc{Default behavior}} 171 | \newcommand{\complexity}{\Fundesc{Complexity}} 172 | \newcommand{\remark}{\Fundesc{Remark}} 173 | \newcommand{\remarks}{\Fundesc{Remarks}} 174 | \newcommand{\note}{\remark} 175 | \newcommand{\notes}{\remarks} 176 | \newcommand{\realnote}{\Fundesc{Note}} 177 | \newcommand{\realnotes}{\Fundesc{Notes}} 178 | \newcommand{\errors}{\Fundesc{Error conditions}} 179 | \newcommand{\sync}{\Fundesc{Synchronization}} 180 | \newcommand{\implimits}{\Fundesc{Implementation limits}} 181 | \newcommand{\replaceable}{\Fundesc{Replaceable}} 182 | \newcommand{\exceptionsafety}{\Fundesc{Exception safety}} 183 | \newcommand{\returntype}{\Fundesc{Return type}} 184 | \newcommand{\cvalue}{\Fundesc{Value}} 185 | \newcommand{\ctype}{\Fundesc{Type}} 186 | \newcommand{\ctypes}{\Fundesc{Types}} 187 | \newcommand{\dtype}{\Fundesc{Default type}} 188 | \newcommand{\ctemplate}{\Fundesc{Class template}} 189 | \newcommand{\templalias}{\Fundesc{Alias template}} 190 | 191 | %% Cross reference 192 | \newcommand{\xref}{\textsc{See also:}\xspace} 193 | \newcommand{\xsee}{\textsc{See:}\xspace} 194 | 195 | %% NTBS, etc. 196 | \newcommand{\NTS}[1]{\textsc{#1}\xspace} 197 | \newcommand{\ntbs}{\NTS{ntbs}} 198 | \newcommand{\ntmbs}{\NTS{ntmbs}} 199 | \newcommand{\ntwcs}{\NTS{ntwcs}} 200 | \newcommand{\ntcxvis}{\NTS{ntc16s}} 201 | \newcommand{\ntcxxxiis}{\NTS{ntc32s}} 202 | 203 | %% Code annotations 204 | \newcommand{\EXPO}[1]{\textit{#1}} 205 | \newcommand{\expos}{\EXPO{exposition only}} 206 | \newcommand{\impdef}{\EXPO{implementation-defined}} 207 | \newcommand{\impdefx}[1]{\indeximpldef{#1}\EXPO{implementation-defined}} 208 | \newcommand{\notdef}{\EXPO{not defined}} 209 | 210 | \newcommand{\UNSP}[1]{\textit{\texttt{#1}}} 211 | \newcommand{\unspec}{\UNSP{unspecified}\xspace} 212 | \newcommand{\unspecbool}{\UNSP{unspecified-bool-type}} 213 | \newcommand{\seebelow}{\UNSP{see below}} 214 | \newcommand{\unspecuniqtype}{\UNSP{unspecified unique type}} 215 | \newcommand{\unspecalloctype}{\UNSP{unspecified allocator type}} 216 | 217 | %% Double underscore 218 | \newcommand{\ungap}{\kern.5pt} 219 | \newcommand{\unun}{\_\ungap\_} 220 | \newcommand{\xname}[1]{\unun\ungap#1} 221 | \newcommand{\mname}[1]{\tcode{\unun\ungap#1\ungap\unun}} 222 | 223 | %% Ranges 224 | \newcommand{\Range}[4]{\tcode{#1\brk{}#3,\brk{}#4\brk{}#2}\xspace} 225 | \newcommand{\crange}[2]{\Range{[}{]}{#1}{#2}} 226 | \newcommand{\brange}[2]{\Range{(}{]}{#1}{#2}} 227 | \newcommand{\orange}[2]{\Range{(}{)}{#1}{#2}} 228 | \newcommand{\range}[2]{\Range{[}{)}{#1}{#2}} 229 | 230 | %% Change descriptions 231 | \newcommand{\diffdef}[1]{\hfill\break\textbf{#1:}\xspace} 232 | \newcommand{\change}{\diffdef{Change}} 233 | \newcommand{\rationale}{\diffdef{Rationale}} 234 | \newcommand{\effect}{\diffdef{Effect on original feature}} 235 | \newcommand{\difficulty}{\diffdef{Difficulty of converting}} 236 | \newcommand{\howwide}{\diffdef{How widely used}} 237 | 238 | %% Miscellaneous 239 | \newcommand{\uniquens}{\textrm{\textit{\textbf{unique}}} } 240 | \newcommand{\stage}[1]{\item{\textbf{Stage #1:}}\xspace} 241 | \newcommand{\doccite}[1]{\textit{#1}\xspace} 242 | \newcommand{\cvqual}[1]{\textit{#1}} 243 | \newcommand{\cv}{\cvqual{cv}} 244 | \renewcommand{\emph}[1]{\textit{#1}\xspace} 245 | \newcommand{\numconst}[1]{\textsl{#1}\xspace} 246 | \newcommand{\logop}[1]{{\footnotesize #1}\xspace} 247 | 248 | %%-------------------------------------------------- 249 | %% Environments for code listings. 250 | 251 | % We use the 'listings' package, with some small customizations. The 252 | % most interesting customization: all TeX commands are available 253 | % within comments. Comments are set in italics, keywords and strings 254 | % don't get special treatment. 255 | 256 | \lstset{language=C++, 257 | basicstyle=\small\CodeStyle, 258 | keywordstyle=, 259 | stringstyle=, 260 | xleftmargin=1em, 261 | showstringspaces=false, 262 | commentstyle=\itshape\rmfamily, 263 | columns=flexible, 264 | keepspaces=true, 265 | texcl=true} 266 | 267 | % Our usual abbreviation for 'listings'. Comments are in 268 | % italics. Arbitrary TeX commands can be used if they're 269 | % surrounded by @ signs. 270 | \newcommand{\CodeBlockSetup}{ 271 | \lstset{escapechar=@} 272 | \renewcommand{\tcode}[1]{\textup{\CodeStylex{##1}}} 273 | \renewcommand{\techterm}[1]{\textit{\CodeStylex{##1}}} 274 | \renewcommand{\term}[1]{\textit{##1}} 275 | \renewcommand{\grammarterm}[1]{\textit{##1}} 276 | } 277 | \lstnewenvironment{codeblock}{\CodeBlockSetup}{} 278 | 279 | % A code block in which single-quotes are digit separators 280 | % rather than character literals. 281 | \lstnewenvironment{codeblockdigitsep}{ 282 | \CodeBlockSetup 283 | \lstset{deletestring=[b]{'}} 284 | }{} 285 | 286 | % Permit use of '@' inside codeblock blocks (don't ask) 287 | \makeatletter 288 | \newcommand{\atsign}{@} 289 | \makeatother 290 | 291 | %%-------------------------------------------------- 292 | %% Indented text 293 | \newenvironment{indented} 294 | {\list{}{}\item\relax} 295 | {\endlist} 296 | 297 | %%-------------------------------------------------- 298 | %% Library item descriptions 299 | \lstnewenvironment{itemdecl} 300 | { 301 | \lstset{escapechar=@, 302 | xleftmargin=0em, 303 | aboveskip=2ex, 304 | belowskip=0ex % leave this alone: it keeps these things out of the 305 | % footnote area 306 | } 307 | } 308 | { 309 | } 310 | 311 | \newenvironment{itemdescr} 312 | { 313 | \begin{indented}} 314 | { 315 | \end{indented} 316 | } 317 | 318 | 319 | %%-------------------------------------------------- 320 | %% Bnf environments 321 | \newlength{\BnfIndent} 322 | \setlength{\BnfIndent}{\leftmargini} 323 | \newlength{\BnfInc} 324 | \setlength{\BnfInc}{\BnfIndent} 325 | \newlength{\BnfRest} 326 | \setlength{\BnfRest}{2\BnfIndent} 327 | \newcommand{\BnfNontermshape}{\small\rmfamily\itshape} 328 | \newcommand{\BnfTermshape}{\small\ttfamily\upshape} 329 | \newcommand{\nonterminal}[1]{{\BnfNontermshape #1}} 330 | 331 | \newenvironment{bnfbase} 332 | { 333 | \newcommand{\nontermdef}[1]{\nonterminal{##1}\indexgrammar{\idxgram{##1}}:} 334 | \newcommand{\terminal}[1]{{\BnfTermshape ##1}\xspace} 335 | \newcommand{\descr}[1]{\normalfont{##1}} 336 | \newcommand{\bnfindentfirst}{\BnfIndent} 337 | \newcommand{\bnfindentinc}{\BnfInc} 338 | \newcommand{\bnfindentrest}{\BnfRest} 339 | \begin{minipage}{.9\hsize} 340 | \newcommand{\br}{\hfill\\} 341 | \frenchspacing 342 | } 343 | { 344 | \nonfrenchspacing 345 | \end{minipage} 346 | } 347 | 348 | \newenvironment{BnfTabBase}[1] 349 | { 350 | \begin{bnfbase} 351 | #1 352 | \begin{indented} 353 | \begin{tabbing} 354 | \hspace*{\bnfindentfirst}\=\hspace{\bnfindentinc}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\hspace{.6in}\=\kill} 355 | { 356 | \end{tabbing} 357 | \end{indented} 358 | \end{bnfbase} 359 | } 360 | 361 | \newenvironment{bnfkeywordtab} 362 | { 363 | \begin{BnfTabBase}{\BnfTermshape} 364 | } 365 | { 366 | \end{BnfTabBase} 367 | } 368 | 369 | \newenvironment{bnftab} 370 | { 371 | \begin{BnfTabBase}{\BnfNontermshape} 372 | } 373 | { 374 | \end{BnfTabBase} 375 | } 376 | 377 | \newenvironment{simplebnf} 378 | { 379 | \begin{bnfbase} 380 | \BnfNontermshape 381 | \begin{indented} 382 | } 383 | { 384 | \end{indented} 385 | \end{bnfbase} 386 | } 387 | 388 | \newenvironment{bnf} 389 | { 390 | \begin{bnfbase} 391 | \list{} 392 | { 393 | \setlength{\leftmargin}{\bnfindentrest} 394 | \setlength{\listparindent}{-\bnfindentinc} 395 | \setlength{\itemindent}{\listparindent} 396 | } 397 | \BnfNontermshape 398 | \item\relax 399 | } 400 | { 401 | \endlist 402 | \end{bnfbase} 403 | } 404 | 405 | % non-copied versions of bnf environments 406 | \newenvironment{ncbnftab} 407 | { 408 | \begin{bnftab} 409 | } 410 | { 411 | \end{bnftab} 412 | } 413 | 414 | \newenvironment{ncsimplebnf} 415 | { 416 | \begin{simplebnf} 417 | } 418 | { 419 | \end{simplebnf} 420 | } 421 | 422 | \newenvironment{ncbnf} 423 | { 424 | \begin{bnf} 425 | } 426 | { 427 | \end{bnf} 428 | } 429 | 430 | %%-------------------------------------------------- 431 | %% Drawing environment 432 | % 433 | % usage: \begin{drawing}{UNITLENGTH}{WIDTH}{HEIGHT}{CAPTION} 434 | \newenvironment{drawing}[4] 435 | { 436 | \newcommand{\mycaption}{#4} 437 | \begin{figure}[h] 438 | \setlength{\unitlength}{#1} 439 | \begin{center} 440 | \begin{picture}(#2,#3)\thicklines 441 | } 442 | { 443 | \end{picture} 444 | \end{center} 445 | \caption{\mycaption} 446 | \end{figure} 447 | } 448 | 449 | %%-------------------------------------------------- 450 | %% Environment for imported graphics 451 | % usage: \begin{importgraphic}{CAPTION}{TAG}{FILE} 452 | 453 | \newenvironment{importgraphic}[3] 454 | {% 455 | \newcommand{\cptn}{#1} 456 | \newcommand{\lbl}{#2} 457 | \begin{figure}[htp]\centering% 458 | \includegraphics[scale=.35]{#3} 459 | } 460 | { 461 | \caption{\cptn}\label{\lbl}% 462 | \end{figure}} 463 | 464 | %% enumeration display overrides 465 | % enumerate with lowercase letters 466 | \newenvironment{enumeratea} 467 | { 468 | \renewcommand{\labelenumi}{\alph{enumi})} 469 | \begin{enumerate} 470 | } 471 | { 472 | \end{enumerate} 473 | } 474 | 475 | % enumerate with arabic numbers 476 | \newenvironment{enumeraten} 477 | { 478 | \renewcommand{\labelenumi}{\arabic{enumi})} 479 | \begin{enumerate} 480 | } 481 | { 482 | \end{enumerate} 483 | } 484 | 485 | %%-------------------------------------------------- 486 | %% Definitions section 487 | % usage: \definition{name}{xref} 488 | %\newcommand{\definition}[2]{\rSec2[#2]{#1}} 489 | % for ISO format, use: 490 | \newcommand{\definition}[2] 491 | {\hfill\vspace{.25ex plus .5ex minus .2ex}\\ 492 | \addtocounter{subsection}{1}% 493 | \textbf{\thesubsection\hfill\relax[#2]}\\ 494 | \textbf{#1}\label{#2}\\ 495 | } 496 | -------------------------------------------------------------------------------- /Coroutines/overloading.tex: -------------------------------------------------------------------------------- 1 | 2 | %% 3 | %% Overloading 4 | %% 5 | %\setcounter{chapter}{12} 6 | \begingroup 7 | \renewcommand{\cleardoublepage}{} 8 | \renewcommand{\clearpage}{} 9 | \rSec0[over]{Overloading} 10 | \endgroup 11 | 12 | \setcounter{section}{3} 13 | \setcounter{subsection}{1} 14 | \setcounter{subsubsection}{1} 15 | %\rSec3[over.match.oper]{Operators in expressions}% 16 | %Add the underlined text to item 3.3. 17 | % 18 | %\begin{quote} 19 | % \setcounter{Paras}{3} 20 | % \begin{itemize} 21 | % \item ... 22 | % \item ... 23 | % \item 24 | %For the operator 25 | %\tcode{,}, 26 | %the unary operator 27 | %\tcode{\&}, 28 | %\added{ 29 | %the unary operator} 30 | %\tcode{\added{co_await}}\added{,} 31 | %or the operator 32 | %\tcode{->}, 33 | %the built-in candidates set is empty. 34 | %For all other operators, the built-in candidates include all 35 | %of the candidate operator functions defined in~\cxxref{over.built} that, 36 | %compared to the given operator, 37 | % \end{itemize} 38 | %\end{quote} 39 | 40 | \setcounter{section}{4} 41 | \rSec1[over.oper]{Overloaded operators} 42 | 43 | Add \tcode{co_await} to the list of operators in paragraph 1 before operators \tcode{()} and \tcode{[]}. 44 | 45 | %\rSec1[over.built]{Built-in operators}% 46 | %\indextext{overloading!built-in operators and} 47 | % 48 | %Add the underlined text to the note in paragraph 1. 49 | % 50 | %\begin{quote} 51 | %\pnum 52 | %The candidate operator functions that represent the built-in operators 53 | %defined in Clause~\ref{expr} are specified in this subclause. 54 | %These candidate 55 | %functions participate in the operator overload resolution process as 56 | %described in~\cxxref{over.match.oper} and are used for no other purpose. 57 | %\enternote 58 | %Because built-in operators\added{ except for operator }\tcode{\added{co_await}} take only operands with non-class type, 59 | %and operator overload resolution occurs only when an operand expression 60 | %originally has class or enumeration type, 61 | %operator overload resolution can resolve to a built-in operator only 62 | %when an operand has a class type that has a user-defined conversion to 63 | %a non-class type appropriate for the operator, or when an operand has 64 | %an enumeration type that can be converted to a type appropriate 65 | %for the operator. 66 | %Also note that some of the candidate operator functions given in this subclause are 67 | %more permissive than the built-in operators themselves. 68 | %As 69 | %described in~\cxxref{over.match.oper}, after a built-in operator is selected 70 | %by overload resolution the expression is subject to the requirements for 71 | %the built-in operator given in Clause~\ref{expr}, and therefore to any 72 | %additional semantic constraints given there. 73 | %If there is a user-written 74 | %candidate with the same name and parameter types as a built-in 75 | %candidate operator function, the built-in operator function 76 | %is hidden and is not included in the set of candidate functions. 77 | %\exitnote 78 | %\end{quote} 79 | % 80 | %Add new paragraph after paragraph 25. 81 | % 82 | %\begin{quote} 83 | %\setcounter{Paras}{25} 84 | %\pnum 85 | %For every pair 86 | %(\textit{T}, 87 | %\textit{CV}), 88 | %where 89 | %\textit{T} 90 | %is a class type containing declarations of any of the following names: \tcode{await_ready}, \tcode{await_suspend}, \tcode{await_resume}, and 91 | %\textit{CQ} 92 | %is \grammarterm{cv-qualifier-seq}, there exist candidate operator functions of the form 93 | %\begin{codeblock} 94 | % @\textit{CV T}@& operator co_await(@\textit{CV T}@&); 95 | % @\textit{CV T}@&& operator co_await(@\textit{CV T}@&&); 96 | %\end{codeblock} 97 | %which return their operand as the result. 98 | %\end{quote} 99 | 100 | Add the following paragraph after paragraph 5. 101 | 102 | \begin{quote} 103 | \setcounter{Paras}{5} 104 | \pnum 105 | The 106 | \tcode{co_await} operator 107 | is described completely in~\ref{expr.await}. 108 | The attributes and restrictions 109 | found in the rest of this subclause do not apply to it unless explicitly 110 | stated in~\ref{expr.await}. 111 | \end{quote} 112 | 113 | %\setcounter{section}{3} 114 | %\setcounter{subsection}{1} 115 | %\setcounter{subsubsection}{1} 116 | %\rSec3[over.match.oper]{Operators in expressions}% 117 | % 118 | %Change \ref{over.match.oper}/9: 119 | % 120 | %\begin{quote} 121 | %\setcounter{Paras}{8} 122 | %\pnum 123 | %If the operator is the operator 124 | %\tcode{,}, 125 | %the unary operator 126 | %\tcode{\&}, 127 | %\removed{or} the operator 128 | %\tcode{->}, 129 | %\added{or the operator \tcode{co_await}}, 130 | %and there are no viable functions, then the operator is 131 | %assumed to be the built-in operator and interpreted according to 132 | %Clause~\ref{expr}. 133 | %\end{quote} 134 | % 135 | %Add a new paragraph after paragraph 8: 136 | % 137 | %\begin{quote} 138 | %\setcounter{Paras}{8} 139 | %\pnum 140 | % When operator \tcode{co_await} returns, the \tcode{co_await} operator is applied to the value returned. The resulting \tcode{co_await} operator is assumed to be the built-in operator and interpreted according to Clause~\ref{expr}. 141 | %\end{quote} 142 | 143 | %\setcounter{subsection}{8} 144 | %\rSec2[over.await]{Await operator}% 145 | % 146 | %\pnum 147 | %If there is no user-declared \tcode{operator await} for type \tcode{X}, but there is a declared member with a name \tcode{await_suspend}, \tcode{await_ready}, or \tcode{await_resume}, then the implementation shall provide the implicit definition of \tcode{operator await} in such a way that the result of the evaluation of an implicit \tcode{operator await(\textit{v})} is \textit{v} itself. 148 | 149 | -------------------------------------------------------------------------------- /Coroutines/p0664r1.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | C++ Coroutine TS Issues 8 | 23 | 24 | 25 |

C++ Coroutine TS Issues

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
Doc. no.P0664R1
RevisesP0664R0
Date:Revised 2017-06-18 at 14:25:00 UTC 38 |
Project:Programming Language C++
Reference:ISO/IEC PDTS 22277, C++ Extensions for Coroutines
Audience:EWG, CWG, LWG
Reply to:Gor Nishanov <gorn@microsoft.com>
57 |

Introduction

58 |

All proposed resolutions wording is relative to N4663 (ISO/IEC PDTS 22277).

59 | 60 |

Table of content

61 | 62 |
    63 |
  • 64 | [CWG Approved Toronto-7/12/2017] Coroutine issues reviewed and approved by CWG: 2 6 7 18 21 65 |
  • 66 |
  • 67 | [LWG Approved Toronto-7/11/2017] Coroutine issues reviewed and approved by LWG: 9 10 11 14 15 22 23 68 |
  • 69 |
    70 | Issues rejected or requiring no action for now: 71 |

    72 |
  • 73 | Core comments requesting rebase of a TS to C++17: 3 5 17 74 |
  • 75 |
  • 76 | Core comments (no action): 4 77 |
  • 78 |
  • 79 | Core comments (rejected, no consensus for change): 8 80 |
  • 81 |
  • 82 | LWG issues with no wording: 12 16 19 20 83 |
  • 84 |
  • 85 | Evolution issues with no wording: 1 13 86 |
87 | 88 | 89 | 90 |

Core Issues (with proposed wording)

91 |
92 | 93 |

2. Change to italics await-resume in 5.3.8/4

94 |

Section: 5.3.8 [expr.await] Status: Has wording 95 | Submitter: US002 Opened: 2017-06-05 Last modified: 2017-06-05

96 |

Proposed resolution:

97 | 98 |

Modify 5.3.8/4

99 |

100 |

The await-expression has the same type and value category as the await-resumeawait-resume expression.

101 |

102 | 103 | [Accepted: Toronto-7/10/2017] 104 | 105 | 106 |

6. Remove or update stateful allocator example in 8.4.4/12

107 |

Section: 8.4.4 [dcl.fct.def.coroutine] Status: Has wording 108 | Submitter: US006 Opened: 2017-06-05 Last modified: 2017-06-05

109 |

Issue:

110 |

111 | Stateful allocators (pmr) do not work this way, there's 112 | no mechanism for allocator propagation to the 113 | captured state. 114 |

115 |

116 | Strike section 12, or provide mechanism for holding allocator. 117 |

118 |

Proposed resolution:

119 | 120 |

Remove example 8.4.4/12

121 | 122 | [Accepted: Toronto-7/10/2017] 123 | 124 | 125 |

7. Fix generator example in 8.4.4/11

126 |

Section: 8.4.4/11 [dcl.fct.def.coroutine] Status: Has wording 127 | Submitter: US007 Opened: 2017-06-05 Last modified: 2017-06-05

128 |

Issue:

129 |

130 | Is unhandled_exception() a requirement for a promise_type? 131 |

132 |

133 | a) Call std::terminate if not present
134 | or
135 | b) Add unhandled_exception() to the complete example 136 | of promise_type in 8.4.4 paragraph 11, the generator 137 | example. 138 |

139 |

Discussion:

140 |

unhandled_exception() is required to be present in a promise_type. 141 | There are more mistakes in the example that are fixed in the proposed resolution. Also, 142 | required includes are added to make the example self contained and runnable in 143 | online compilers.

144 |

Proposed resolution:

145 | Modify the example in 8.4.4/11 as follows: 146 |
147 |
148 | #include <iostream>
149 | #include <experimental/coroutine>
150 | 
151 | // ::operator new(size_t, nothrow_t) will be used if allocation is needed
152 | struct generator {
153 |   struct promise_type;
154 |   using handle = std::experimental::coroutine_handle<promise_type>;
155 |   struct promise_type {
156 |     int current_value;
157 |     static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
158 |     auto get_return_object() { return generator{handle::from_promise(*this)}; }
159 |     auto initial_suspend() { return std::experimental::suspend_always{}; }
160 |     auto final_suspend() { return std::experimental::suspend_always{}; }
161 |     void unhandled_exception() { std::terminate(); }
162 |     void return_void() {}
163 |     auto yield_value(int value) {
164 |       current_value = value;
165 |       return std::experimental::suspend_always{};
166 |     }
167 |   };
168 |   bool move_next() { return coro ? (coro.resume(), !coro.done()) : false; }
169 |   int current_value() { return coro.promise().current_value; }
170 |   generator(generator const&) = delete;
171 |   generator(generator && rhs) : coro(rhs.coro) { rhs.coro = nullptr; }
172 |   ~generator() { if (coro) coro.destroy(); }
173 | private:
174 |   generator(handle h) : coro(h) {}
175 |   handle coro;
176 | };
177 | generator f() { co_yield 1; co_yield 2; }
178 | int main() {
179 |   auto g = f();
180 |   while (g.move_next()) std::cout << g.current_value() << std::endl;
181 | }
182 | 
183 |
184 | 185 | [Accepted: Toronto-7/10/2017] 186 | 187 | 188 |

18. In intro.refs use required text from ISO directive part2

189 |

Section: 2 [intro.refs] Status: Has wording 190 | Submitter: CA018 Opened: 2017-06-05 Last modified: 2017-06-05

191 |

Issue:

192 |

193 | The form required by ISO/IEC Directives, Part 2, 2016 subclause 15.5.1 is not followed. 194 |

195 |

196 | Use the text provided by the Directives. 197 |

198 |

Proposed resolution:

199 | 200 |

Modify [intro.refs] paragraph 1 as follows:

201 |

202 | The following referenced document is indispensable for the 203 | application of this document. For dated references, only the 204 | edition cited applies.
205 | The following documents are referred to in the text in such a way that some or all of their 206 | content constitutes requirements of this document. For dated references, only the edition cited applies. 207 | For undated references, the latest edition of the referenced document (including any amendments) applies. 208 |
209 | 210 | [Accepted: Toronto-7/10/2017] 211 | 212 | 213 |

21. Wording of 'co_return <expr>;' statement for expressions of type void implies that <expr> is not evaluated

214 |

Section: 6.6.3.1 [stmt.return.coroutine] Status: Has wording 215 | Submitter: Lewis Baker Opened: 2017-03-11 Last modified: 2017-06-19

216 |

Issue:

217 |

218 | This wording seems to indicate that expr is not evaluated in co_return expr if the expression has type void, 219 | since expr does not occur in the translation. I assume this was not the intention here.

220 |

221 | Perhaps there needs to be an extra case here to explicitly state what co_return expr; translates to if the type of expr 222 | is void? 223 | 224 |

Proposed resolution:

225 | 226 |

Modify paragraph 2 in [stmt.return.coroutine] follows:

227 |

228 | 2. ... where final_suspend is as defined in 8.4.4 and S is an expression defined as follows:
229 | (2.1) — S is p.return_value(braced-init-list), if the operand is a braced-init-list;
230 | (2.2) — S is p.return_value(expression), if the operand is an expression of non-void type;
231 | 232 | (2.3) — S is { expressionopt ; p.return_void(); }, otherwise;
233 | 234 |
235 | 236 | [Accepted: Toronto-7/12/2017] 237 | 238 |
239 | 240 |

Core comments requesting rebase to C++17

241 |
242 | 243 |

3. Update range based for statement after C++17

244 |

Section: 6.5.4/1 [stmt.ranged]Status: Comment 245 | Submitter: US003 Opened: 2017-06-05 Last modified: 2017-06-05

246 |

Comment:

247 |

Update range based for statement after C++17

248 | 249 | [Rejected. Will rebase prior to merge to working paper. Toronto-7/10/2017] 250 | 251 |

5. Modify co_return grammar to match C++17

252 |

Section: 6.6.3.1 [stmt.return.coroutine]Status: Comment 253 | Submitter: US005 Opened: 2017-06-05 Last modified: 2017-06-05

254 |

Comment:

255 |

Simplify the grammar for 256 |

257 | coroutine-return-statement:
258 |    co_return expression_opt_;
259 |    co_return braced-init-list;
260 |     
261 | to 262 |
coroutine-return-statement:
263 |    co_return co_return expr-or-braced-init-list opt;
264 |     
265 |

266 | [Rejected. Will rebase prior to merge to working paper. Toronto-7/10/2017] 267 | 268 |

17. Rebase entire TS on C++17

269 |

Section: Status: Comment 270 | Submitter: US017 Opened: 2017-06-05 Last modified: 2017-06-05

271 |

Comment:

272 |

We are in the process of balloting the final text of the 273 | next C++ standard, provisionally ISO/IEC 14882:2017. 274 | We should hold back publishing this TS long enough to 275 | rebase on the text of the new standard. 276 |

277 |

278 | Other than updating this reference, the change is 279 | almost entirely updating section numbers and crossreferences. 280 | The normative changes would be

281 |
    282 |
  • updating the range based 'for' loop syntax;
  • 283 |
  • the text for a 'return' statement would need adjusting;
  • 284 |
  • the wording on restrictions with respect to longjmp 285 | should be reviewed;
  • 286 |
  • hash support for coroutine_handle should be updated 287 | with the “enabled” terminology.
  • 288 |
289 | 290 | [Rejected. Will rebase prior to merge to working paper. Toronto-7/10/2017] 291 |
292 | 293 |

Core comments (no action)

294 |
295 | 296 |

4. It would be good to minimize undefined 297 | behaviour

298 |

Section: 6.6.3 6.6.3.1 8.4.4 8.11.2.5 18.10 18.11.2.5 Status: Comment 299 | Submitter: US004 Opened: 2017-06-05 Last modified: 2017-06-05

300 |

Comment:

301 |

302 | There are many new cases of undefined behaviour 303 | introduced by the TS which are somewhat easily triggered by independent parts of the mechanisms, 304 | e.g., the result type of the coroutine interacting 305 | through the promise_type to allow flow of control to 306 | run off the end of a coroutine. 307 | In general it would be good to minimize undefined 308 | behaviour.

309 |

310 | No action for now. However, experience with TS 311 | implementation may allow reducing UB. This should form part of any review for integrating coroutines as 312 | part of a future standard. 313 |

314 | 315 | [No Action. Toronto-7/10/2017] 316 |
317 | 318 |

Core comments (rejected, no consensus for change)

319 |
320 | 321 | 322 | 323 |

8. Note about possibly undefined behaviour

324 |

Section: 8.4.4/11 [dcl.fct.def.coroutine] Status: Has wording 325 | Submitter: US008 Opened: 2017-06-05 Last modified: 2017-06-05

326 |

Proposed change:

327 |

328 | Modify note in 8.4.4/11: 329 |

330 | If a coroutine has a parameter passed by reference, 331 | resuming the coroutine 332 | after the lifetime of the entity referred to by that 333 | parameter has ended is likely to results in 334 | undefined behavior. 335 |
336 |

337 |

Proposed resolution:

338 | 339 | No change. If after resumption a coroutine does not touch that parameter, there is no 340 | undefined behavior. 341 |

342 | [Reject. No consensus for change. Toronto-7/10/2017] 343 | 344 |
345 |

LWG Issues (with proposed wording)

346 |
347 | 348 | 349 |

9. Move row in the language support table

350 |

Section: 18.1 [support.general] Table 30 Status: Has wording 351 | Submitter: CA009 Opened: 2017-06-05 Last modified: 2017-06-05

352 | 353 |

Issue:

354 | The entry for subclause 18.11 appears before the entry for subclause 18.10. 355 | 356 |

Proposed resolution:

357 | Move the insertion of the entry for subclause 18.11 358 | to appear after the entry for subclause 18.10. 359 |

360 | [Accepted. Toronto-7/11/2017] 361 | 362 | 363 |

10. Specify the exact behaviour of user-customization of 364 | coroutine_traits.

365 |

Section: 18.11.1 [coroutine.traits] Status: Has wording 366 | Submitter: US010 Opened: 2017-06-05 Last modified: 2017-06-05

367 | 368 |

Issue:

369 | Is the template coroutines_traits intended to be a 370 | user-extension point? If so, spell out the contract 371 | for users to customize this trait. Otherwise, restrict 372 | user specialization with the wording for all type 373 | traits in the header. 18.11.1p2 374 | suggests the former, while the latter is much 375 | simpler to specify for the initial TS. 376 | 377 |

Proposed resolution:

378 |
    379 |
  1. 380 | Modify paragraph 2 of 18.11.1 [coroutine.traits] as follows 381 |
    382 | 2. Users may specialize coroutine_traits to customize the semantics of coroutines.
    383 | 2. A program may specialize this template. Such specialization shall define a publicly accessible nested type named promise_type. 384 |
    385 |
  2. 386 |
  3. 387 | In 18.11.2 [coroutine.handle] add paragraph: 388 |
    389 | 2. The behavior of a program that adds specializations for coroutine_handle is undefined. 390 |
    391 |
  4. 392 |
393 | 394 |
395 | [Accepted. Toronto-7/11/2017] 396 | 397 | 398 |

11. coroutine_handle: Unclear where specification refer to specialization or primary template

399 |

Section: 18.1.2 [coroutine.handle] Status: Comment 400 | Submitter: US011 Opened: 2017-06-05 Last modified: 2017-06-05

401 | 402 |

Issue:

403 | The specification of each operation is not explicitly 404 | clear whether it applied to the specialization of 405 | coroutine_handle<void>, or the primary 406 | coroutine_handle template. 407 |

408 | Break this section into two, to clearly provide definitions 409 | for both versions of the template. 410 |

411 | 412 |

Proposed resolution:

413 | Use resolution for 23 414 | 415 |

416 | [Accepted. Toronto-7/11/2017] 417 | 418 | 419 |

14. Comment about: a concurrent resumption of a coroutine by multiple 420 | threads may result in a data race

421 |

Section: 18.11.2.5 Status: Comment 422 | Submitter: US014 Opened: 2017-06-05 Last modified: 2017-06-05

423 | 424 |

Comment:

425 | a concurrent resumption of a coroutine by multiple 426 | threads may result in a data race

427 | Possibly means concurrent destruction here, in the 428 | destroy method. 429 |

430 | 431 |

Discussion:

432 | Yes. Any combination of resumptions may result in a data race: resume/resume, resume/destroy or destroy/destroy. 433 |

Proposed wording:

434 | 435 |
    436 |
  1. 437 | Modify paragraph 3 of 18.11.2.5 [coroutine.handle.resumption] as follows: 438 |
    439 | 3. Synchronization: a concurrent resumption of a coroutine by multiple threads may result in a data race.
    440 | a concurrent resumption of the coroutine via resume, operator(), or destroy may result in a data race. 441 |
    442 |
  2. 443 |
  3. 444 | Modify paragraph 6 of 18.11.2.5 [coroutine.handle.resumption] as follows: 445 |
    446 | 3. Synchronization: a concurrent resumption of a coroutine by multiple threads may result in a data race.
    447 | a concurrent resumption of the coroutine via resume, operator(), or destroy may result in a data race. 448 |
    449 |
  4. 450 |
451 | 452 |
453 | [Accepted. Toronto-7/11/2017] 454 | 455 | 456 |

15. Make coroutine_handle comparison constexpr

457 |

Section: 18.11.2.7 Status: Comment 458 | Submitter: US015 Opened: 2017-06-05 Last modified: 2017-06-05

459 | 460 |

Comment:

461 | As coroutine_handle<void> is a literal type, should 462 | the comparison operators be constexpr?

463 | Add constexpr to the declaration/definition of 464 | operator==, operator !=, operator<, operator<=, 465 | operator>=, and operator> for arguments of type 466 | coroutine_handle<>. 467 |

468 | 469 |

Discussion:

470 | The only literal coroutine_handle is the default constructed one. Not sure if we need constexpr on comparisons. (LEWG voted 3 5 11 3 0 to add constexpr) 471 |

Proposed wording:

472 | Modify function declarations in clause 18.11.2.7 [coroutine.handle.compare] as follows: 473 | 474 |
475 | constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
476 | constexpr bool operator<(coroutine_handle<> x, coroutine_handle<> y) noexcept;
477 | constexpr bool operator!=(coroutine_handle<> x, coroutine_handle<> y) noexcept;
478 | constexpr bool operator>(coroutine_handle<> x, coroutine_handle<> y) noexcept;
479 | constexpr bool operator<=(coroutine_handle<> x, coroutine_handle<> y) noexcept;
480 | constexpr bool operator>=(coroutine_handle<> x, coroutine_handle<> y) noexcept;
481 |
482 | 483 |
484 | [Accepted. Toronto-7/11/2017] 485 | 486 | 487 |

22. Rename [coroutine.handle.import.export] to [coroutine.handle.export.import] for consistency

488 |

Section: 18.11 [support.coroutine] Status: Has wording 489 | Submitter: Bryce Lelbach Opened: 2017-03-10 Last modified: 2017-06-19

490 | 491 |

Issue:

492 | In the class synopsis for coroutine_handle<> in [coroutine.handle], this section is referred to as "export/import", and the export function (address) is listed before the import function (from_address). Likewise, in the definitions for these two methods in [coroutine.handle.import.export], the section is titled "Export/import" and address appears first. Since from_address mentions address, this seems like the correct order to list things in as it avoids adding forward references to the spec. 493 | 494 | I'd like to rename this stable tag from [coroutine.handle.import.export] to [coroutine.handle.export.import] as an editorial change before PTDS. 495 | 496 |

Pull request.

497 | 498 |

Proposed resolution:

499 |
500 |
s/coroutine.handle.import.export/coroutine.handle.export.import/g
501 |
502 | 503 | [Accepted. Toronto-7/11/2017] 504 | 505 | 506 |

23. coroutine_handle::from_address - consolidate duplicate definitions, add missing constexpr and replace address() with address in precondition wording

507 |

Section: 18.11.2 [coroutine.handle] Status: Has wording 508 | Submitter: Bryce Lelbach Opened: 2017-03-10 Last modified: 2017-06-19

509 | 510 |

Issue:

511 |

512 | There are currently two definitions of the from_address: one in [coroutine.handle.import.export] and one in [coroutine.handle.import]. 513 | In the class synopses in [coroutine.handle], the coroutine_handle<> specialization references [coroutine.handle.import.export] 514 | while primary definition for coroutine_handle references [corouinte.handle.import]. 515 | They are nearly identical in wording. although the definition in [coroutine.handle.import.export] is written as if it was out of line 516 | (e.g. coroutine_handle<>::from_address). 517 | Even though the primary template of coroutine_handle inherits from coroutine_handle<> it is necessary to define from_address 518 | in the primary template, since, from_address returns coroutine_handle, which is a different type in the primary template than it is 519 | in coroutine_handle. 520 |

521 |

522 | from_address's Requires: paragraph in [coroutine.handle.import.export] states the pre-condition that 523 | "addr was obtained via a prior call to address()". It should be address, not address(), 524 | since address() is an expression not a method 525 |

526 |

527 | from_address is declared constexpr in the class synopsis ([coroutine.handle], 528 | in both the primary template and the specialization for coroutine_handle<>) but is not constexpr in the definition. 529 | The design intent, I believe, is for from_address to be constexpr.

530 |

Pull request.

531 |

Proposed resolution:

532 |
    533 |
  1. 534 | Modify 18.11.2 [coroutine.handle] primary template synopsis: 535 |
    536 |
    537 |     // 18.11.2.3 import
    538 |     // 18.11.2.2 export/import
    539 |     constexpr static coroutine_handle from_address(void* addr);
    540 | 
    541 |
    542 |
  2. 543 |
  3. 544 | Modify 18.11.2.2 [coroutine.handle.import.export] as follows: 545 |
    546 |
    547 |     constexpr static coroutine_handle<> coroutine_handle<>::from_address(void* addr);
    548 |     constexpr static coroutine_handle<Promise> coroutine_handle<Promise<::from_address(void* addr);
    549 |     Requires: addr was obtained via a prior call to address().
    550 |   
    551 |
    552 |
  4. 553 |
  5. 554 | Remove section 18.11.2.3 [coroutine.handle.import]. 555 |
  6. 556 |
557 | 558 | [Accepted. Toronto-7/11/2017] 559 | 560 | 561 |
562 |

LWG Issues (no wording)

563 |
564 | 565 | 566 | 567 |

12. Should there be a coroutine_handle type with ownership semantic?

568 |

Section: 18.1.2 [coroutine.handle] Status: Comment 569 | Submitter: US012 Opened: 2017-06-05 Last modified: 2017-06-05

570 | 571 |

Comment:

572 | Coroutine handles have essentially raw pointer 573 | semantics. Should there be a library type as part of 574 | the TS that does destroy / set to nullptr? 575 |

576 | If a library type is needed, please add it. 577 |

578 | 579 |

Discussion:

580 | coroutine handle is a low level type. Ownership semantic is introduced by higher level types such as a generator or task. 581 | Note that not every use of coroutine_handle requires ownership semantic. An iterator does not own the coroutine nor a coroutine_handle 582 | captured by a lambda passed as a callback parameter to an asynchronous API owns the coroutine it refers to. 583 |

Proposed resolution:

584 | No action 585 | 586 |

587 | [Reject. No consensus for change. Toronto-7/11/2017] 588 | 589 | 590 |

16. Rename suspend_always to suspend_always_t and suspend_never to suspend_never_t

591 |

Section: 18.11.3 Status: Comment 592 | Submitter: US016 Opened: 2017-06-05 Last modified: 2017-06-05

593 | 594 |

Comment:

595 | The names suspend_never and suspend_always 596 | should be (inline) constexpr variables of type 597 | suspend_never_t and suspend_always_t 598 | respectively. 599 |

600 | Change suspend_never and suspend_always as 601 | appropriate. 602 |

603 | 604 |

Discussion:

605 | Most common pattern observed in the wild for these types are: 606 |
607 |   struct promise_type {
608 |     suspend_never initial_suspend() { return {}; }
609 |     suspend_always yield_value(int value) { ...; return {}; }
610 |     ...
611 |   };
612 | 
613 | Suggested change makes the common case more verbose. 614 |

Proposed resolution:

615 | No action 616 | 617 |

618 | [Reject. No consensus for change. Toronto-7/11/2017] 619 | 620 | 621 |

19. Add higher-level coroutine types

622 |

Section: Status: Comment 623 | Submitter: US019 Opened: 2017-06-05 Last modified: 2017-06-05

624 | 625 |

Comment:

626 | The TS presents only low level mechanisms to 627 | implement coroutines. For final release in a C++ 628 | standard, standard library implementations of 629 | generators, futures from coroutines, guard types for 630 | handles, etc. should also ship. 631 |

632 | Please consider adding standard library 633 | implementations of generators, futures from 634 | Coroutines, guard types for handles and any others that 635 | may be needed when Coroutines are incorporated into 636 | the C++ Standard. 637 |

638 | 639 |

Discussion:

640 | Yes. We plan to add generator and adapters for network TS and concurrency TS. 641 |

Proposed resolution:

642 | No immediate action for PDTS 643 | 644 |

645 | [Accept. No action for now. Toronto-7/11/2017] 646 | 647 | 648 |

20. Disallow storing coroutines in std::function objects that discard their result.

649 |

Section: Status: Comment 650 | Submitter: US020 Opened: 2017-06-05 Last modified: 2017-06-05

651 | 652 |

Comment:

653 | Coroutines are invokable types, can they be stored 654 | by a std::function? What about a 655 | std::function<void()> that discards the result on 656 | invocation? 657 |

658 | Disallow storing coroutines in std::function objects 659 | that discard their result. 660 |

661 | 662 |

Discussion:

663 | Yes, coroutines are functions and they can be stored in a std::function. 664 | Storing a coroutine in a std::function objects that discard their result is no different than 665 | storing a function with the same signature as coroutine in std::function. 666 |

Proposed resolution:

667 | No action 668 | 669 |

670 | [Reject. No consensus for change. Toronto-7/11/2017] 671 | 672 |
673 | 674 |

Evolution Issues (no wording)

675 |
676 | 677 |

1. Support stackful coroutines

678 |

Section: Status: Comment 679 | Submitter: CH001 Opened: 2017-06-05 Last modified: 2017-06-05

680 |

Issue:

681 |

682 | This TS disallows stackful coroutines. This is too 683 | restrictive and stackful coroutines should be allowed as 684 | well. 685 |

686 |

687 | Allow as suspension context functions that were called from a top-level coroutine. 688 |

689 | 690 |
691 | [Reject. No consensus for change. Toronto-7/10/2017] 692 | 693 | 694 |

13. Allow both return_void and return_value

695 |

Section: Status: Comment 696 | Submitter: US013 Opened: 2017-06-05 Last modified: 2017-06-05

697 |

Comment:

698 |

699 | Promise types are required to implement either 700 | return_value() or return_void(), but not both, and it is 701 | undefined behaviour for a coroutine to run off the end, 702 | where return_void would be called.

703 |

704 | Consider implementing both either_return() and 705 | return_value() for promise types, and eliminate the 706 | undefined behaviour. 707 |

708 |

Discussion:

709 | The design intent of having one or the other to make sure that co_return 710 | behavior in a coroutine is similar to that of return in a regular function. 711 | Allowing both would allow this code to compile: 712 |
713 |   coro f(bool cond) {
714 |     if (cond)
715 |       co_return 42;
716 |     else
717 |       co_return;
718 |   }
719 | 
720 | which we would like to avoid. 721 |

Proposed Resolution:

722 | No change 723 | 724 |

725 | [Reject. No consensus for change. Toronto-7/11/2017] 726 | 727 | 728 | 729 | -------------------------------------------------------------------------------- /Coroutines/special.tex: -------------------------------------------------------------------------------- 1 | 2 | \begingroup 3 | \renewcommand{\cleardoublepage}{} 4 | \renewcommand{\clearpage}{} 5 | \rSec0[special]{Special member functions} 6 | \endgroup 7 | 8 | \setcounter{section}{0} 9 | \rSec1[class.ctor]{Constructors}% 10 | 11 | Add new paragraph after paragraph 10. 12 | 13 | \setcounter{Paras}{10} 14 | \begin{quote} 15 | \pnum A constructor shall not be a coroutine. 16 | \end{quote} 17 | 18 | \setcounter{section}{3} 19 | \rSec1[class.dtor]{Destructors}% 20 | 21 | Add new paragraph after paragraph 16. 22 | 23 | \setcounter{Paras}{16} 24 | \begin{quote} 25 | \pnum A destructor shall not be a coroutine. 26 | \end{quote} 27 | 28 | \pagebreak 29 | 30 | \setcounter{section}{7} 31 | \rSec1[class.copy]{Copying and moving class objects}% 32 | \setcounter{subsection}{2} 33 | \rSec2[class.copy.elision]{Copy/move elision}% 34 | 35 | Add a bullet to paragraph 1: 36 | 37 | \begin{quote} 38 | \begin{itemize} 39 | \item in a coroutine (\ref{dcl.fct.def.coroutine}), a copy of a coroutine parameter can be omitted 40 | and references to that copy replaced with references to the corresponding parameter if the meaning of the program will 41 | be unchanged except for the execution of a constructor and destructor for the parameter copy object 42 | \end{itemize} 43 | \end{quote} 44 | 45 | Modify paragraph 3 as follows: 46 | 47 | \begin{quote} 48 | \setcounter{Paras}{2} 49 | \pnum 50 | In the following copy-initialization contexts, a move operation might be used instead of a copy operation: 51 | \begin{itemize} 52 | \item If the \grammarterm{expression} in a \tcode{return} \added{or } \tcode{\added{co_return}} statement \iref{stmt.return} 53 | is a (possibly parenthesized) \grammarterm{id-expression} 54 | that names an object with automatic storage duration declared in the body 55 | or \grammarterm{parameter-declaration-clause} of the innermost enclosing 56 | function or \grammarterm{lambda-expression}, or 57 | 58 | \item if the operand of a \grammarterm{throw-expression}\cxxref{expr.throw} 59 | is the name of a non-volatile automatic object 60 | (other than a function or catch-clause parameter) 61 | whose scope does not extend beyond the end of the innermost enclosing 62 | \grammarterm{try-block} (if there is one), 63 | \end{itemize} 64 | overload resolution to select the constructor 65 | for the copy \added{or the }\tcode{\added{return_value}}\added{ overload to call} is first performed as if the object were designated by an 66 | rvalue. 67 | If the first overload resolution fails or was not performed, 68 | or if the type of the first parameter of the selected 69 | constructor \added{or }\tcode{\added{return_value}}\added{ overload }is not an rvalue reference to the object's type (possibly cv-qualified), 70 | overload resolution is performed again, considering the object as an lvalue. 71 | \begin{note} 72 | This two-stage overload resolution must be performed regardless 73 | of whether copy elision will occur. It determines the constructor \added{or }\tcode{\added{return_value}}\added{ overload }to be called if 74 | elision is not performed, and the selected constructor \added{or }\tcode{\added{return_value}}\added{ overload }must be accessible even if 75 | the call is elided. 76 | \end{note} 77 | 78 | \end{quote} 79 | -------------------------------------------------------------------------------- /Coroutines/statements.tex: -------------------------------------------------------------------------------- 1 | \begingroup 2 | \renewcommand{\cleardoublepage}{} 3 | \renewcommand{\clearpage}{} 4 | \rSec0[stmt.stmt]{Statements}% 5 | \endgroup 6 | 7 | \setcounter{section}{4} 8 | \rSec1[stmt.iter]{Iteration statements}% 9 | Add the underlined text to paragraph 1. 10 | %NOTE: change the grammar 11 | 12 | \begin{quote} 13 | \pnum 14 | Iteration statements specify looping. 15 | 16 | \indextext{statement!\idxcode{while}}% 17 | \indextext{statement!\idxcode{do}}% 18 | \indextext{statement!\idxcode{for}}% 19 | % 20 | \begin{bnf} 21 | \nontermdef{iteration-statement}\br 22 | \terminal{while (} condition \terminal{)} statement\br 23 | \terminal{do} statement \terminal{while (} expression \terminal{) ;}\br 24 | \terminal{for (} for-init-statement condition\opt \terminal{;} expression\opt \terminal{)} statement\br 25 | \terminal{for} \terminal{\added{co_await\opt{}}} 26 | \terminal{(} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement\br 27 | % \added{\terminal{cofor (} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement} 28 | \end{bnf} 29 | \end{quote} 30 | 31 | % goes inside and need fixing goes after 32 | 33 | \setcounter{subsection}{3} 34 | \rSec2[stmt.ranged]{The range-based \tcode{for} statement}% 35 | \indextext{statement!range~based \idxcode{for}} 36 | 37 | Add the underlined text to paragraph 1. 38 | 39 | \begin{quote} 40 | \setcounter{Paras}{0} 41 | \pnum 42 | For a range-based \tcode{for} statement of the form 43 | 44 | \begin{ncbnf} 45 | \terminal{for} \terminal{\added{co_await\opt{}}} \terminal{(} for-range-declaration : for-range-initializer \terminal{)} statement 46 | \end{ncbnf} 47 | 48 | %let \textit{range-init} be equivalent to the \grammarterm{expression} surrounded 49 | %by parentheses\footnote{this ensures that a top-level comma operator cannot be 50 | % reinterpreted as a delimiter between \grammarterm{init-declarator}{s} in the 51 | % declaration of \tcode{__range}.} 52 | % 53 | %\begin{ncbnf} 54 | % \terminal{(} expression \terminal{)} 55 | %\end{ncbnf} 56 | % 57 | %and for a range-based \tcode{for} statement of the form 58 | % 59 | %\begin{ncbnf} 60 | % \terminal{for} \terminal{\added{co_await\opt{}}} \terminal{(} for-range-declaration \terminal{:} braced-init-list \terminal{)} statement 61 | %\end{ncbnf} 62 | % 63 | %let \textit{range-init} be equivalent to the \grammarterm{braced-init-list}. In each case, a 64 | %range-based \tcode{for} statement 65 | is equivalent to 66 | 67 | %\begin{codeblock} 68 | % { 69 | % auto && __range = @\textit{for-range-initializer}@; 70 | % for ( auto __begin = @\added{\tcode{co_await}\opt{}}@ begin-expr, 71 | % __end = end-expr; 72 | % __begin != __end; 73 | % @\added{\tcode{co_await}\opt{}}@ ++__begin ) { 74 | % @\textit{for-range-declaration}@ = *__begin; 75 | % @\textit{statement}@ 76 | % } 77 | % } 78 | %\end{codeblock} 79 | 80 | \begin{ncbnftab} 81 | \terminal{\{}\br 82 | \>\terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br 83 | \>\terminal{auto __begin =} \terminal{\added{co_await\opt{}}} begin-expr \terminal{;}\br 84 | \>\terminal{auto __end =} end-expr \terminal{;}\br 85 | \>\terminal{for ( ; __begin != __end; \terminal{\added{co_await\opt{}}} ++__begin ) \{}\br 86 | \>\>for-range-declaration \terminal{= *__begin;}\br 87 | \>\>statement\br 88 | \>\terminal{\}}\br 89 | \terminal{\}} 90 | \end{ncbnftab} 91 | \end{quote} 92 | 93 | Insert a new bullet after paragraph 1 bullet 1. 94 | 95 | \begin{quote} 96 | \begin{itemize} 97 | \item 98 | if the \grammarterm{for-range-initializer} is an \grammarterm{expression}, 99 | it is regarded as if it were surrounded by parentheses (so that a comma operator 100 | cannot be reinterpreted as delimiting two \grammarterm{init-declarator}{s}); 101 | \item \added{\tcode{co_await} is present if and only if it appears immediately after the \tcode{for} keyword;} 102 | \item \tcode{__range}, \tcode{__begin}, and \tcode{__end} are variables defined for 103 | exposition only; and ... 104 | \end{itemize} 105 | \end{quote} 106 | 107 | %\tcode{\added{co_await}}\added{ is present if and only if it appears immediately after the \tcode{for} keyword, and}\linebreak 108 | %\tcode{__range}, \tcode{__begin}, and \tcode{__end} are variables defined for 109 | %exposition only, and \tcode{_RangeT} is the type of the 110 | %\grammarterm{}{expression}, and \textit{begin-expr} and \textit{end-expr} are 111 | %determined as follows: ... 112 | 113 | %\ednote{The remainder of paragraph 1 remains unchanged and is not included here.} 114 | 115 | 116 | 117 | Add the following paragraph after paragraph 2. 118 | 119 | \begin{quote} 120 | \setcounter{Paras}{2} 121 | \pnum 122 | A range-based \tcode{for} statement with \tcode{co_await} shall appear only within a suspension context of a function (\ref{expr.await}). 123 | \end{quote} 124 | %\setcounter{subsection}{4} 125 | %\rSec2[stmt.for.await]{The \tcode{cofor} statement}% 126 | % 127 | %Add this section to \ref{stmt.iter}. 128 | % 129 | % 130 | %\begin{quote} 131 | %\pnum 132 | %A \tcode{cofor} statement of the form 133 | % 134 | %\begin{ncbnf} 135 | % \terminal{cofor (} for-range-declaration : expression \terminal{)} statement 136 | %\end{ncbnf} 137 | %is equivalent to 138 | % 139 | %\begin{codeblock} 140 | % { 141 | % auto && __range = range-init; 142 | % for ( auto __begin = co_await begin-expr, 143 | % + __end = end-expr; 144 | % __begin != __end; 145 | % co_await ++__begin ) { 146 | % @\textit{for-range-declaration}@ = *__begin; 147 | % @\textit{statement}@ 148 | % } 149 | % } 150 | %\end{codeblock} 151 | % 152 | %where \tcode{__range}, \tcode{__begin}, \tcode{__end}, 153 | %\textit{range-init}, \textit{begin-expr}, and \textit{end-expr} are defined as in the range-based \tcode{for} statement (\cxxref{stmt.ranged}). 154 | % 155 | %\end{quote} 156 | \pagebreak 157 | \setcounter{section}{5} 158 | \rSec1[stmt.jump]{Jump statements}% 159 | 160 | %In paragraph 1 add two productions to the grammar: 161 | Add \grammarterm{coroutine-return-statement} to the grammar production \grammarterm{jump-statement}: 162 | 163 | \begin{quote} 164 | \begin{bnf} 165 | \nontermdef{jump-statement}\br 166 | \terminal{break ;}\br 167 | \terminal{continue ;}\br 168 | \terminal{return} expr-braced-init-list\opt \terminal{;}\br 169 | \added{coroutine-return-statement} \br 170 | \terminal{goto} identifier \terminal{;} 171 | \end{bnf} 172 | \end{quote} 173 | 174 | Add the underlined text to paragraph 2: 175 | 176 | \begin{quote} 177 | \setcounter{Paras}{1} 178 | \pnum 179 | On exit from a scope (however accomplished), objects with automatic storage 180 | duration~(\cxxref{basic.stc.auto}) that have been constructed in that scope are destroyed 181 | in the reverse order of their construction. 182 | \added{ 183 | \enternote 184 | A suspension of a coroutine (\ref{expr.await}) is not considered to be an exit from a scope. 185 | \exitnote 186 | } 187 | ... 188 | \end{quote} 189 | 190 | \setcounter{subsection}{2} 191 | \rSec2[stmt.return]{The \tcode{return} statement}% 192 | \indextext{\idxcode{return}}% 193 | \indextext{function~return|see{\tcode{return}}}% 194 | 195 | %Add the underlined text to paragraph 1: 196 | % 197 | %\begin{quote} 198 | %\pnum 199 | %A function returns to its caller by the \tcode{return} statement\added{; that function shall not be a coroutine (\ref{dcl.fct.def.coroutine}).} 200 | %\added{A return statement shall not appear in a coroutine. A coroutine return statement shall be used instead \ref{stmt.return.coroutine}.} 201 | %\added{In this section, function refers to a function that is not a coroutine. The \tcode{return} statement in a coroutine described in section \ref{stmt.return.coroutine}.} 202 | % \added{A \tcode{return} statement shall not appear in a coroutine.} 203 | %\added{Using a \tcode{return} statement in a coroutine makes the program ill-formed.} 204 | %\end{quote} 205 | 206 | Add the underlined text to paragraph 2: 207 | 208 | \begin{quote} 209 | \setcounter{Paras}{1} 210 | \pnum ... Flowing off the end of 211 | a constructor, 212 | a destructor, or 213 | a function \added{that is not a coroutine} with a \cv{}~\tcode{void} return type is 214 | equivalent to a \tcode{return} with no operand. Otherwise, flowing off the end of a function other than main (\cxxref{basic.start.main}) \added{or a coroutine (\ref{dcl.fct.def.coroutine})} 215 | results in undefined behavior. 216 | \end{quote} 217 | 218 | %NOTE 219 | 220 | %Add a note: 221 | % 222 | %\begin{quote} 223 | %\enternote 224 | %In this section a function refers to non-coroutines only. 225 | %The return statement in coroutines is described in \ref{stmt.return.coroutine} 226 | %\exitnote 227 | %\end{quote} 228 | 229 | %Modify paragraphs 1 through 3 as follows. 230 | % 231 | %\begin{quote} 232 | %\pnum 233 | %A function returns to its caller by the \tcode{return} statement. 234 | %\added{A coroutine also returns to its caller 235 | %when suspended at suspend-resume point.} 236 | % 237 | %\pnum 238 | %\added{In a non-coroutine a}\removed{A} return statement 239 | %with neither an \grammarterm{expression} nor a \grammarterm{braced-init-list} 240 | %can be used only in functions 241 | %that do not return a value, that is, a function with the return type 242 | %\cv\ \tcode{void}, a constructor~(\cxxref{class.ctor}), or a 243 | %destructor~(\cxxref{class.dtor}). 244 | %\indextext{\idxcode{return}!constructor~and}% 245 | %\indextext{\idxcode{return}!constructor~and}% 246 | %\added{In a coroutine a return statement 247 | % with neither an \grammarterm{expression} nor a \grammarterm{braced-init-list} 248 | % can be used only in functions 249 | % with eventual return type \tcode{void}.} 250 | %A return statement with an expression of non-void type can be used only 251 | %in \added{non-coroutine} functions returning a value 252 | %\added{or coroutines returning an eventual value}; the value of the expression is returned 253 | %to the caller of the function. 254 | %\indextext{conversion!return~type}% 255 | %The value of the expression is implicitly converted to the return type of the 256 | %function in which it appears. A return statement can involve the 257 | %construction and copy or move of a temporary object~(\cxxref{class.temporary}). 258 | %\enternote 259 | %A copy or move operation associated with a return statement may be elided or 260 | %considered as an rvalue for the purpose of overload resolution in 261 | %selecting a constructor~(\cxxref{class.copy}). 262 | %\exitnote A return statement with a \grammarterm{braced-init-list} initializes the object or reference to be returned from the function by copy-list-initialization~(\cxxref{dcl.init.list}) from the specified initializer list. \enterexample 263 | % 264 | %\begin{codeblock} 265 | % std::pair f(const char* p, int x) { 266 | % return {p,x}; 267 | % } 268 | %\end{codeblock} 269 | %\exitexample 270 | % 271 | %Flowing off the end of a function is equivalent to a \tcode{return} with 272 | %no value; this results in undefined behavior in a value-returning 273 | %\added{non-coroutine} function \added{or in an eventual-value-returning coroutine}. 274 | % 275 | %\pnum 276 | %A return statement with an expression of type \tcode{void} 277 | %can be used only in \added{non-coroutine} functions with a return type of 278 | %\cvqual{cv} \tcode{void} \added{or coroutines with eventual return type of \tcode{void}}; 279 | %the expression is evaluated just before the function 280 | %returns to its caller. 281 | %\end{quote} 282 | % 283 | %%Add underlined text to paragraph 1: 284 | %%\pnum 285 | %%A function returns to its caller by the \tcode{return} statement 286 | %%\added{or by reaching suspend-resume-point}. 287 | % 288 | %Add paragraph 4. 289 | % 290 | %\begin{quote} 291 | %\setcounter{Paras}{3} 292 | %\pnum 293 | %In a coroutine return statement is replaced with 294 | %a call to __pr.set_result, where _p 295 | %\end{quote} 296 | 297 | \rSec3[stmt.return.coroutine]{The \tcode{co_return} statement}% 298 | 299 | Add this subclause to \ref{stmt.return}. 300 | 301 | \begin{quote} 302 | %\enternote 303 | %In this section function refers to coroutine only. 304 | %The return statement in non-coroutines is described in \ref{stmt.return} 305 | %\exitnote 306 | 307 | \begin{bnf} 308 | \nontermdef{coroutine-return-statement}\br 309 | \terminal{co_return} expr-or-braced-init-list\opt \terminal{;}\br 310 | \end{bnf} 311 | 312 | \pnum 313 | A coroutine returns to its caller or resumer (\ref{dcl.fct.def.coroutine}) by the \tcode{co_return} statement 314 | or when suspended (\ref{expr.await}). A coroutine shall not return to its caller or resumer by a \tcode{return} statement (\ref{stmt.return}). 315 | 316 | \pnum 317 | The \grammarterm{expr-braced-init-list} of a \tcode{co_return} statement is called its operand. 318 | Let $p$ be an lvalue naming the coroutine promise object (\ref{dcl.fct.def.coroutine}) and $P$ be the type of that object, 319 | then a \tcode{co_return} statement is equivalent to: 320 | 321 | %Let $P$ be the coroutine promise type (\ref{dcl.fct.def.coroutine}) and $p$ be an lvalue naming the coroutine promise object (\ref{dcl.fct.def.coroutine}), 322 | 323 | %the the \grammarterm{unqualified-id}{s} 324 | %\tcode{return_void} and \tcode{return_value} are looked up in the scope of class $P$. 325 | %If both are found, the program is ill-formed. If none are found, the coroutine does not have an eventual return type. 326 | %If \tcode{return_void} was found, the coroutine has an eventual return type of \tcode{void}. 327 | %If \tcode{return_value} was found, the coroutine has non-void eventual return type. 328 | %\pnum 329 | 330 | \begin{codeblock} 331 | { @$S$@; goto @$final{\_}suspend$@; } 332 | \end{codeblock} 333 | 334 | where $final$\tcode{\_}$suspend$ is as defined in \ref{dcl.fct.def.coroutine} and $S$ is defined as follows: 335 | 336 | \begin{itemize} 337 | \item $S$ is $p$\tcode{.return_value(}\grammarterm{expr-or-braced-init-list}{}\tcode{)}, if the operand is a \grammarterm{braced-init-list} or an expression of non-\tcode{void} type; 338 | % \item $S$ is $p$\tcode{.return_value(}\grammarterm{expression}{}\tcode{)}, if the operand is an expression of non-\tcode{void} type; 339 | \item $S$ is \tcode{\{}{ }\grammarterm{expression}\opt \tcode{;} $p$\tcode{.return_void()}\tcode{;{ }\}}, otherwise; 340 | \end{itemize} 341 | $S$ shall be a prvalue of type \tcode{void}. 342 | 343 | \pnum 344 | If $p$\tcode{.return_void()} is a valid expression, flowing off the end of a coroutine is equivalent to a \tcode{co_return} with no operand; otherwise flowing off the end of a coroutine results in undefined behavior. 345 | %If none are found, the coroutine does not have an eventual return type. 346 | % $expression$ is treated as an xvalue; 347 | 348 | % this is fishy ^^^^ 349 | 350 | %\enternote 351 | %If coroutine instance lifetime is controlled 352 | %by a RAII object, it is expected that \tcode{_Pr.final_suspend()} returns true 353 | %and coroutine state will be destroyed when 354 | %destructor of an owner object runs. 355 | % 356 | %For detached tasks, where lifetime of the coroutine ends 357 | %when the task completes, \tcode{_Pr.final_suspend()} would return false. 358 | %\exitnote 359 | 360 | \end{quote} 361 | 362 | %\rSec2[stmt.yield]{The \tcode{yield} statement}% 363 | % 364 | %Add this section to \ref{stmt.jump}. 365 | % 366 | %\begin{quote} 367 | % 368 | %Let \textit{yielded value} be the operand of the \tcode{co_yield} statement and \textit{p} be the promise object of the enclosing coroutine. 369 | %If the result type of \tcode{\textit{p}.yield_value(\textit{yielded-value})} is of type \cvvoid, then the \tcode{co_yield} statement is equivalent to: 370 | % 371 | %\begin{codeblock} 372 | % @\textit{p}@.yield_value(@\textit{yielded-value}@); 373 | % @\textit{suspend-resume-point} 374 | %\end{codeblock} 375 | % 376 | %otherwise, it is equivalent to: 377 | % 378 | %\begin{codeblock} 379 | % if (@\textit{p}@.yield_value(@\textit{yielded-value}@)) { 380 | % @\textit{suspend-resume-point}@ 381 | % } 382 | % 383 | %\end{codeblock} 384 | 385 | %\pnum 386 | %A \tcode{co_yield} statement may only appear if a \tcode{yield_value} member 387 | %function is defined in the promise type of the enclosing coroutine. 388 | 389 | %NOTE: not pretty, can we remove the duplication 390 | %NOTE: make if first 391 | % 392 | %\pnum 393 | %\enternote 394 | %A promise object may have more than one overload of a \tcode{yield_value}. 395 | % 396 | %\enterexample 397 | %\begin{codeblock} 398 | % recursive_generator flatten(node* n) 399 | % { 400 | % if (n == nullptr) 401 | % return; 402 | % 403 | % co_yield flatten(n->left); 404 | % co_yield n->value; 405 | % co_yield flatten(n->right); 406 | % } 407 | %\end{codeblock} 408 | % 409 | %The promise for the \tcode{flatten} function should contain overloads that can accept a value of type \tcode{int} and a value of type \tcode{recursive_generator}. 410 | %In the former case, yielding a value is unconditional. In the latter case, the nested generator may produce an empty sequence of values and thus suspension at the yield point no yielding occurs and \tcode{yield_value} should return \tcode{false}. 411 | %\exitexample 412 | %\exitnote 413 | 414 | %\end{quote} -------------------------------------------------------------------------------- /Coroutines/styles.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | %% styles.tex -- set styles for: 3 | % chapters 4 | % pages 5 | % footnotes 6 | 7 | %%-------------------------------------------------- 8 | %% create chapter style 9 | 10 | \makechapterstyle{cppstd}{% 11 | \renewcommand{\beforechapskip}{\onelineskip} 12 | \renewcommand{\afterchapskip}{\onelineskip} 13 | \renewcommand{\chapternamenum}{} 14 | \renewcommand{\chapnamefont}{\chaptitlefont} 15 | \renewcommand{\chapnumfont}{\chaptitlefont} 16 | \renewcommand{\printchapternum}{\chapnumfont\thechapter\quad} 17 | \renewcommand{\afterchapternum}{} 18 | } 19 | 20 | %%-------------------------------------------------- 21 | %% create page styles 22 | 23 | \makepagestyle{cpppage} 24 | \makeevenhead{cpppage}{\copyright\,\textsc{ISO/IEC}}{}{\textbf{\docno}} 25 | \makeoddhead{cpppage}{\copyright\,\textsc{ISO/IEC}}{}{\textbf{\docno}} 26 | \makeevenfoot{cpppage}{\leftmark}{}{\thepage} 27 | \makeoddfoot{cpppage}{\leftmark}{}{\thepage} 28 | %\makeevenfoot{cpppage}{}{}{\thepage} 29 | %\makeoddfoot{cpppage}{}{}{\thepage} 30 | 31 | \makeatletter 32 | \makepsmarks{cpppage}{% 33 | \let\@mkboth\markboth 34 | \def\chaptermark##1{\markboth{##1}{##1}}% 35 | \def\sectionmark##1{\markboth{% 36 | \ifnum \c@secnumdepth>\z@ 37 | \textsection\space\thesection 38 | \fi 39 | }{\rightmark}}% 40 | \def\subsectionmark##1{\markboth{% 41 | \ifnum \c@secnumdepth>\z@ 42 | \textsection\space\thesubsection 43 | \fi 44 | }{\rightmark}}% 45 | \def\subsubsectionmark##1{\markboth{% 46 | \ifnum \c@secnumdepth>\z@ 47 | \textsection\space\thesubsubsection 48 | \fi 49 | }{\rightmark}}% 50 | \def\paragraphmark##1{\markboth{% 51 | \ifnum \c@secnumdepth>\z@ 52 | \textsection\space\theparagraph 53 | \fi 54 | }{\rightmark}}} 55 | \makeatother 56 | 57 | \aliaspagestyle{chapter}{cpppage} 58 | 59 | %%-------------------------------------------------- 60 | %% set heading styles for main matter 61 | \newcommand{\beforeskip}{-.7\onelineskip plus -1ex} 62 | \newcommand{\afterskip}{.3\onelineskip minus .2ex} 63 | 64 | \setbeforesecskip{\beforeskip} 65 | \setsecindent{0pt} 66 | \setsecheadstyle{\large\bfseries\raggedright} 67 | \setaftersecskip{\afterskip} 68 | 69 | \setbeforesubsecskip{\beforeskip} 70 | \setsubsecindent{0pt} 71 | \setsubsecheadstyle{\large\bfseries\raggedright} 72 | \setaftersubsecskip{\afterskip} 73 | 74 | \setbeforesubsubsecskip{\beforeskip} 75 | \setsubsubsecindent{0pt} 76 | \setsubsubsecheadstyle{\normalsize\bfseries\raggedright} 77 | \setaftersubsubsecskip{\afterskip} 78 | 79 | \setbeforeparaskip{\beforeskip} 80 | \setparaindent{0pt} 81 | \setparaheadstyle{\normalsize\bfseries\raggedright} 82 | \setafterparaskip{\afterskip} 83 | 84 | \setbeforesubparaskip{\beforeskip} 85 | \setsubparaindent{0pt} 86 | \setsubparaheadstyle{\normalsize\bfseries\raggedright} 87 | \setaftersubparaskip{\afterskip} 88 | 89 | %%-------------------------------------------------- 90 | % set heading style for annexes 91 | \newcommand{\Annex}[3]{\chapter[#2]{(#3)\protect\\#2\hfill[#1]}\relax\label{#1}} 92 | \newcommand{\infannex}[2]{\Annex{#1}{#2}{informative}} 93 | \newcommand{\normannex}[2]{\Annex{#1}{#2}{normative}} 94 | 95 | %%-------------------------------------------------- 96 | %% set footnote style 97 | \footmarkstyle{\smaller#1) } 98 | 99 | %%-------------------------------------------------- 100 | % set style for main text 101 | \setlength{\parindent}{0pt} 102 | \setlength{\parskip}{1ex} 103 | \setlength{\partopsep}{-1.5ex} 104 | 105 | %%-------------------------------------------------- 106 | %% set caption style and delimiter 107 | \captionstyle{\centering} 108 | \captiondelim{ --- } 109 | % override longtable's caption delimiter to match 110 | \makeatletter 111 | \def\LT@makecaption#1#2#3{% 112 | \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{% 113 | \sbox\@tempboxa{#1{#2 --- }#3}% 114 | \ifdim\wd\@tempboxa>\hsize 115 | #1{#2 --- }#3% 116 | \else 117 | \hbox to\hsize{\hfil\box\@tempboxa\hfil}% 118 | \fi 119 | \endgraf\vskip\baselineskip}% 120 | \hss}}} 121 | \makeatother 122 | 123 | %%-------------------------------------------------- 124 | %% set global styles that get reset by \mainmatter 125 | \newcommand{\setglobalstyles}{ 126 | \counterwithout{footnote}{chapter} 127 | \counterwithout{table}{chapter} 128 | \counterwithout{figure}{chapter} 129 | \renewcommand{\chaptername}{} 130 | \renewcommand{\appendixname}{Annex } 131 | } 132 | 133 | %%-------------------------------------------------- 134 | %% change list item markers to number and em-dash 135 | 136 | \renewcommand{\labelitemi}{---\parabullnum{Bullets1}{\labelsep}} 137 | \renewcommand{\labelitemii}{---\parabullnum{Bullets2}{\labelsep}} 138 | \renewcommand{\labelitemiii}{---\parabullnum{Bullets3}{\labelsep}} 139 | \renewcommand{\labelitemiv}{---\parabullnum{Bullets4}{\labelsep}} 140 | 141 | %%-------------------------------------------------- 142 | %% set section numbering limit, toc limit 143 | \maxsecnumdepth{subparagraph} 144 | \setcounter{tocdepth}{1} 145 | -------------------------------------------------------------------------------- /Coroutines/support.tex: -------------------------------------------------------------------------------- 1 | 2 | %\setcounter{chapter}{17} 3 | \rSec0[language.support]{Language support library} 4 | 5 | \rSec1[support.general]{General} 6 | 7 | Add a row to Table~\ref{tab:lang.sup.lib.summary} for coroutine support header \tcode{}. 8 | 9 | \setcounter{table}{31} 10 | \begin{libsumtab}{Language support library summary}{tab:lang.sup.lib.summary} 11 | \cxxref{support.types} & Types & \tcode{} \\ \rowsep 12 | & & \tcode{} \\ 13 | \cxxref{support.limits} & Implementation properties & \tcode{} \\ 14 | & & \tcode{} \\ \rowsep 15 | \cxxref{cstdint} & Integer types & \tcode{} \\ \rowsep 16 | \cxxref{support.start.term} & Start and termination & \tcode{} \\ \rowsep 17 | \cxxref{support.dynamic} & Dynamic memory management & \tcode{} \\ \rowsep 18 | \cxxref{support.rtti} & Type identification & \tcode{} \\ \rowsep 19 | \cxxref{support.exception} & Exception handling & \tcode{} \\ \rowsep 20 | \cxxref{support.initlist} & Initializer lists & \tcode{} \\ \rowsep 21 | & & \tcode{} \\ 22 | & & \tcode{} \\ 23 | & & \tcode{} \\ 24 | \cxxref{support.runtime} & Other runtime support & \tcode{} \\ 25 | & & \tcode{} \\ 26 | & & \tcode{} \\ 27 | & & \tcode{} \\ \rowsep 28 | \added{\ref{support.coroutine}} 29 | & \added{Coroutines support} 30 | & \added{\tcode{}} \\ 31 | 32 | \end{libsumtab} 33 | 34 | 35 | \setcounter{section}{10} 36 | \setcounter{subsection}{1} 37 | \rSec2[csetjmp.syn]{Header \tcode{} synopsis} 38 | 39 | Add underlined text to paragraph 2. 40 | 41 | \begin{quote} 42 | \setcounter{Paras}{3} 43 | \pnum 44 | The function signature 45 | \indexlibrary{\idxcode{longjmp}}% 46 | \tcode{longjmp(jmp_buf jbuf, int val)} 47 | has more restricted behavior in this International Standard. 48 | A \tcode{setjmp}/\tcode{longjmp} call pair has undefined 49 | behavior if replacing the \tcode{setjmp} and \tcode{longjmp} 50 | by \tcode{catch} and \tcode{throw} would invoke any non-trivial destructors for any automatic 51 | objects. 52 | % 53 | \added{A call to \tcode{setjmp} or \tcode{longjmp} has undefined 54 | behavior if invoked in a suspension context of a coroutine (\ref{expr.await}).} 55 | 56 | \xref ISO C~7.13. 57 | \end{quote} 58 | 59 | \setcounter{section}{10} 60 | \rSec1[support.coroutine]{Coroutines support library} 61 | 62 | Add this subclause to Clause \ref{language.support}. 63 | 64 | \begin{quote} 65 | 66 | \pnum 67 | The header 68 | \tcode{} 69 | defines several types providing compile and run-time support for coroutines in a \Cpp program. 70 | 71 | \synopsis{Header \tcode{} synopsis} 72 | 73 | \indextext{\idxhdr{coroutine}}% 74 | \indexlibrary{\idxhdr{coroutine}}% 75 | \begin{codeblock} 76 | namespace std { 77 | namespace experimental { 78 | inline namespace coroutines_v1 { 79 | 80 | // \ref{coroutine.traits} coroutine traits 81 | template 82 | struct coroutine_traits; 83 | 84 | // \ref{coroutine.handle} coroutine handle 85 | template 86 | struct coroutine_handle; 87 | 88 | // \ref{coroutine.promise.noop} noop coroutine promise 89 | struct noop_coroutine_promise; 90 | template <> struct coroutine_handle; 91 | // noop coroutine handle 92 | using noop_coroutine_handle = coroutine_handle; 93 | 94 | // \ref{coroutine.noop} noop coroutine 95 | noop_coroutine_handle noop_coroutine() noexcept; 96 | 97 | // \ref{coroutine.handle.compare} comparison operators: 98 | constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept; 99 | constexpr bool operator!=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 100 | constexpr bool operator<(coroutine_handle<> x, coroutine_handle<> y) noexcept; 101 | constexpr bool operator>(coroutine_handle<> x, coroutine_handle<> y) noexcept; 102 | constexpr bool operator<=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 103 | constexpr bool operator>=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 104 | 105 | // \ref{coroutine.trivial.awaitables} trivial awaitables 106 | struct suspend_never; 107 | struct suspend_always; 108 | 109 | } // namespace coroutines_v1 110 | } // namespace experimental 111 | 112 | // \ref{coroutine.handle.hash} hash support: 113 | template struct hash; 114 | template struct hash>; 115 | 116 | } // namespace std 117 | \end{codeblock} 118 | 119 | \rSec2[coroutine.traits]{Coroutine traits} 120 | \pnum 121 | This subclause defines requirements on classes representing 122 | \term{coroutine traits}, 123 | and defines the class template 124 | \tcode{coroutine_traits} 125 | that satisfies those requirements. 126 | 127 | %\pnum 128 | %Coroutines need a set of related types and functions 129 | %to complete the definition of their semantics. 130 | %These types and functions are provided as a set of member types or typedefs 131 | %and functions in the instantiation of struct template 132 | %\tcode{coroutine_traits}. This subclause defines the semantics of these 133 | %members. 134 | 135 | %\removed{\pnum 136 | %Users may specialize \tcode{coroutine_traits} 137 | %to customize the semantics of coroutines.} 138 | 139 | %\rSec3[coroutine.traits.requirements]{Coroutine traits requirements} 140 | %\pnum 141 | %In Table~\ref{tab:coroutine.traits.requirements}, X denotes 142 | %a trait class instantiated as described in \ref{dcl.fct.def.coroutine}. 143 | % 144 | %; 145 | %If a coroutine is a member function, then $a_1$ denotes the implicit \tcode{this} parameter, $a_2$, ... $a_n$ refer to explicit parameters of the coroutine, otherwise, $a_1$, $a_2$, ... $a_n$ denote the parameters of the coroutine. 146 | % 147 | %\begin{concepttable}{Coroutine traits requirements}{tab:coroutine.traits.requirements} 148 | % {p{1.6in}p{4.15in}} 149 | % \topline 150 | % Expression & Behavior \\ \capsep 151 | % \tcode{X::promise_type} & 152 | % \tcode{X::promise_type} must be a type satisfying coroutine promise requirements (\ref{coroutine.promise}) 153 | %\\ 154 | %\end{concepttable} 155 | 156 | \rSec3[coroutine.traits.primary]{Class template \tcode{coroutine_traits}} 157 | \pnum The header \tcode{} defines 158 | the primary template \tcode{coroutine_traits} such that 159 | if \tcode{ArgTypes} is a parameter pack of types and 160 | if the \grammarterm{qualified-id} \tcode{R::promise_type} is valid and 161 | denotes a type (\cxxref{temp.deduct}), 162 | then 163 | \tcode{coroutine_traits} has the following publicly accessible member: 164 | 165 | \begin{codeblock} 166 | using promise_type = typename R::promise_type; 167 | \end{codeblock} 168 | 169 | Otherwise, \tcode{coroutine_traits} has no members. 170 | 171 | \pnum Program defined specializations of this template shall define a publicly accessible nested type named \tcode{promise_type}. 172 | 173 | %\pnum A user specialization of \tcode{coroutine_traits} shall have a valid member type \tcode{promise_type}. 174 | 175 | \rSec2[coroutine.handle]{Class template \tcode{coroutine_handle}} 176 | 177 | \indexlibrary{\idxcode{coroutine_handle}}% 178 | \begin{codeblock} 179 | namespace std { 180 | namespace experimental { 181 | inline namespace coroutines_v1 { 182 | 183 | template <> 184 | struct coroutine_handle 185 | { 186 | // \ref{coroutine.handle.con} construct/reset 187 | constexpr coroutine_handle() noexcept; 188 | constexpr coroutine_handle(nullptr_t) noexcept; 189 | coroutine_handle& operator=(nullptr_t) noexcept; 190 | 191 | // \ref{coroutine.handle.export.import} export/import 192 | constexpr void* address() const noexcept; 193 | constexpr static coroutine_handle from_address(void* addr); 194 | 195 | // \ref{coroutine.handle.observers} observers 196 | constexpr explicit operator bool() const noexcept; 197 | bool done() const; 198 | 199 | // \ref{coroutine.handle.resumption} resumption 200 | void operator()() const; 201 | void resume() const; 202 | void destroy() const; 203 | 204 | private: 205 | void* ptr; // exposition only 206 | }; 207 | 208 | template 209 | struct coroutine_handle : coroutine_handle<> 210 | { 211 | // \ref{coroutine.handle.con} construct/reset 212 | using coroutine_handle<>::coroutine_handle; 213 | static coroutine_handle from_promise(Promise&); 214 | coroutine_handle& operator=(nullptr_t) noexcept; 215 | 216 | // \ref{coroutine.handle.export.import} export/import 217 | constexpr static coroutine_handle from_address(void* addr); 218 | 219 | // \ref{coroutine.handle.promise} promise access 220 | Promise& promise() const; 221 | }; 222 | 223 | template <> struct coroutine_handle : coroutine_handle<> 224 | { 225 | // \ref{coroutine.handle.noop.observers} noop observers 226 | constexpr explicit operator bool() const noexcept; 227 | constexpr bool done() const noexcept; 228 | 229 | // \ref{coroutine.handle.noop.resumption} noop resumption 230 | constexpr void operator()() const noexcept; 231 | constexpr void resume() const noexcept; 232 | constexpr void destroy() const noexcept; 233 | 234 | // \ref{coroutine.handle.noop.promise} noop promise access 235 | noop_coroutine_promise& promise() const noexcept; 236 | 237 | // \ref{coroutine.handle.noop.address} noop address 238 | constexpr void* address() const noexcept; 239 | private: 240 | coroutine_handle(@\textit{unspecified}@); 241 | }; 242 | 243 | } // namespace coroutines_v1 244 | } // namespace experimental 245 | } // namespace std 246 | \end{codeblock} 247 | 248 | \pnum 249 | Let \textit{P} be the promise type of a coroutine (\ref{dcl.fct.def.coroutine}). An object of type \tcode{coroutine_handle<\textit{P}>} is called a \term{coroutine handle} 250 | and can be used to refer to a suspended or executing coroutine. 251 | A default constructed \tcode{coroutine_handle} object does not refer to any coroutine. 252 | 253 | \pnum If a program declares an explicit or partial specialization of \tcode{coroutine_handle}, the behavior is undefined. 254 | 255 | %Such a function is called a \textit{target} of a coroutine handle. 256 | %A default constructed \tcode{coroutine_handle} object has no target. 257 | 258 | 259 | \rSec3[coroutine.handle.con]{\tcode{coroutine_handle} construct/reset} 260 | \begin{itemdecl} 261 | constexpr coroutine_handle() noexcept; 262 | constexpr coroutine_handle(nullptr_t) noexcept; 263 | \end{itemdecl} 264 | \begin{itemdescr} 265 | \pnum\postconditions \tcode{address() == nullptr}. 266 | \end{itemdescr} 267 | 268 | \begin{itemdecl} 269 | static coroutine_handle from_promise(Promise& p); 270 | \end{itemdecl} 271 | \begin{itemdescr} 272 | \pnum 273 | \precondition \tcode{p} is a reference to a promise object of a coroutine. 274 | 275 | \pnum 276 | \returns A coroutine handle $h$ referring to the coroutine. 277 | 278 | \pnum\postconditions \tcode{addressof(}$h$\tcode{.promise()) == addressof(p)}. 279 | \end{itemdescr} 280 | 281 | \begin{itemdecl} 282 | coroutine_handle& operator=(nullptr_t) noexcept; 283 | \end{itemdecl} 284 | \begin{itemdescr} 285 | \pnum\postconditions \tcode{address() == nullptr}. 286 | 287 | \pnum\returns \tcode{*this}. 288 | \end{itemdescr} 289 | 290 | \rSec3[coroutine.handle.export.import]{\tcode{coroutine_handle} export/import} 291 | 292 | \begin{itemdecl} 293 | constexpr void* address() const noexcept; 294 | \end{itemdecl} 295 | 296 | \begin{itemdescr} 297 | \pnum 298 | \returns \tcode{ptr}. 299 | \end{itemdescr} 300 | 301 | 302 | \begin{itemdecl} 303 | constexpr static coroutine_handle<> coroutine_handle<>::from_address(void* addr); 304 | constexpr static coroutine_handle coroutine_handle::from_address(void* addr); 305 | \end{itemdecl} 306 | 307 | \begin{itemdescr} 308 | \pnum 309 | \precondition \tcode{addr} was obtained via a prior call to \tcode{address}. 310 | 311 | \pnum 312 | \postconditions \tcode{from_address(address()) == *this}. 313 | \end{itemdescr} 314 | 315 | \rSec3[coroutine.handle.observers]{\tcode{coroutine_handle} observers} 316 | \begin{itemdecl} 317 | constexpr explicit operator bool() const noexcept; 318 | \end{itemdecl} 319 | 320 | \begin{itemdescr} 321 | \pnum 322 | \returns \tcode{address() != nullptr}. 323 | \end{itemdescr} 324 | 325 | \begin{itemdecl} 326 | bool done() const; 327 | \end{itemdecl} 328 | \begin{itemdescr} 329 | \pnum 330 | \precondition \tcode{*this} refers to a suspended coroutine. 331 | 332 | \pnum 333 | \returns \tcode{true} if the coroutine is suspended 334 | at its final suspend point, otherwise \tcode{false}. 335 | \end{itemdescr} 336 | 337 | \rSec3[coroutine.handle.resumption]{\tcode{coroutine_handle} resumption} 338 | \begin{itemdecl} 339 | void operator()() const; 340 | void resume() const; 341 | \end{itemdecl} 342 | \begin{itemdescr} 343 | \pnum 344 | \precondition \tcode{*this} refers to a suspended coroutine. 345 | 346 | \pnum 347 | \effects Resumes the execution of the coroutine. If the coroutine was suspended 348 | at its final suspend point, behavior is undefined. 349 | 350 | \pnum 351 | \enternote A concurrent resumption of the coroutine via \tcode{resume}, \tcode{operator()}, or \tcode{destroy} may result in a data race. 352 | \exitnote 353 | \end{itemdescr} 354 | 355 | \begin{itemdecl} 356 | void destroy() const; 357 | \end{itemdecl} 358 | \begin{itemdescr} 359 | \pnum 360 | \precondition \tcode{*this} refers to a suspended coroutine. 361 | 362 | \pnum 363 | \effects Destroys the coroutine (\ref{dcl.fct.def.coroutine}). 364 | 365 | \pnum 366 | \enternote A concurrent resumption of the coroutine via \tcode{resume}, \tcode{operator()}, or \tcode{destroy} may result in a data race. 367 | \exitnote 368 | \end{itemdescr} 369 | 370 | \rSec3[coroutine.handle.promise]{\tcode{coroutine_handle} promise access} 371 | \begin{itemdecl} 372 | Promise& promise() const; 373 | \end{itemdecl} 374 | 375 | \begin{itemdescr} 376 | \pnum 377 | \precondition \tcode{*this} refers to a coroutine. 378 | 379 | \pnum 380 | \returns A reference to the promise of the coroutine. 381 | \end{itemdescr} 382 | 383 | \rSec3[coroutine.handle.compare]{Comparison operators} 384 | 385 | \begin{itemdecl} 386 | constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept; 387 | \end{itemdecl} 388 | 389 | \begin{itemdescr} 390 | \pnum 391 | \returns \tcode{x.address() == y.address()}. 392 | \end{itemdescr} 393 | 394 | \begin{itemdecl} 395 | constexpr bool operator!=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 396 | \end{itemdecl} 397 | 398 | \begin{itemdescr} 399 | \pnum 400 | \returns \tcode{!(x == y)}. 401 | \end{itemdescr} 402 | 403 | \begin{itemdecl} 404 | constexpr bool operator<(coroutine_handle<> x, coroutine_handle<> y) noexcept; 405 | \end{itemdecl} 406 | 407 | \begin{itemdescr} 408 | \pnum 409 | \returns \tcode{less<>()(x.address(), y.address())}. 410 | \end{itemdescr} 411 | 412 | \begin{itemdecl} 413 | constexpr bool operator>(coroutine_handle<> x, coroutine_handle<> y) noexcept; 414 | \end{itemdecl} 415 | 416 | \begin{itemdescr} 417 | \pnum 418 | \returns \tcode{(y < x)}. 419 | \end{itemdescr} 420 | 421 | \begin{itemdecl} 422 | constexpr bool operator<=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 423 | \end{itemdecl} 424 | 425 | \begin{itemdescr} 426 | \pnum 427 | \returns \tcode{!(x > y)}. 428 | \end{itemdescr} 429 | 430 | \begin{itemdecl} 431 | constexpr bool operator>=(coroutine_handle<> x, coroutine_handle<> y) noexcept; 432 | \end{itemdecl} 433 | 434 | \begin{itemdescr} 435 | \pnum 436 | \returns \tcode{!(x < y)}. 437 | \end{itemdescr} 438 | 439 | \rSec3[coroutine.handle.hash]{Hash support} 440 | 441 | \begin{itemdecl} 442 | template struct hash>; 443 | \end{itemdecl} 444 | 445 | \begin{itemdescr} 446 | \pnum 447 | %The template specialization shall meet the requirements of class template hash (\cxxref{unord.hash}). 448 | The specialization is enabled\iref{unord.hash}. 449 | \end{itemdescr} 450 | 451 | \rSec3[coroutine.handle.noop.observers]{\tcode{noop_coroutine_handle} observers} 452 | \begin{itemdecl} 453 | constexpr explicit operator bool() const noexcept; 454 | \end{itemdecl} 455 | 456 | \begin{itemdescr} 457 | \pnum 458 | \returns \tcode{true}. 459 | \end{itemdescr} 460 | 461 | \begin{itemdecl} 462 | constexpr bool done() const noexcept; 463 | \end{itemdecl} 464 | 465 | \begin{itemdescr} 466 | \pnum 467 | \returns \tcode{false}. 468 | \end{itemdescr} 469 | 470 | \rSec3[coroutine.handle.noop.resumption]{\tcode{noop_coroutine_handle} resumption} 471 | \begin{itemdecl} 472 | constexpr void operator()() const noexcept; 473 | constexpr void resume() const noexcept; 474 | constexpr void destroy() const noexcept; 475 | \end{itemdecl} 476 | 477 | \begin{itemdescr} 478 | \pnum 479 | \effects None. 480 | 481 | \pnum 482 | \remarks If \tcode{noop_coroutine_handle} is converted to \tcode{coroutine_handle<>}, calls to \tcode{operator()}, \tcode{resume} and \tcode{destroy} on that handle will also have no observable effects. 483 | \end{itemdescr} 484 | 485 | \rSec3[coroutine.handle.noop.promise]{\tcode{noop_coroutine_handle} promise access} 486 | \begin{itemdecl} 487 | noop_coroutine_promise& promise() const noexcept; 488 | \end{itemdecl} 489 | 490 | \begin{itemdescr} 491 | \pnum 492 | \returns A reference to the promise object associated with this coroutine handle. 493 | \end{itemdescr} 494 | 495 | \rSec3[coroutine.handle.noop.address]{\tcode{noop_coroutine_handle} address} 496 | \begin{itemdecl} 497 | constexpr void* address() const noexcept; 498 | \end{itemdecl} 499 | 500 | \begin{itemdescr} 501 | \pnum 502 | \returns \tcode{ptr}. 503 | 504 | \pnum 505 | \remarks A \tcode{noop_coroutine_handle}'s \tcode{ptr} is always a non-\tcode{null} pointer value. 506 | \end{itemdescr} 507 | 508 | \rSec2[coroutine.promise.noop]{Class \tcode{noop_coroutine_promise}} 509 | \begin{itemdecl} 510 | struct noop_coroutine_promise {}; 511 | \end{itemdecl} 512 | 513 | \begin{itemdescr} 514 | \pnum The class \tcode{noop_coroutine_promise} defines the promise type for the coroutine referred to by \tcode{noop_coroutine_handle} (\ref{support.coroutine}). 515 | \end{itemdescr} 516 | 517 | \rSec2[coroutine.noop]{Function \tcode{noop_coroutine}} 518 | 519 | \begin{itemdecl} 520 | noop_coroutine_handle noop_coroutine() noexcept; 521 | \end{itemdecl} 522 | 523 | \begin{itemdescr} 524 | \pnum\returns A handle to a coroutine that has no observable effects when resumed or destroyed. 525 | 526 | \pnum\remarks A handle returned from \tcode{noop_coroutine} may or may not compare equal to a handle returned from another invocation of \tcode{noop_coroutine}. 527 | \end{itemdescr} 528 | 529 | \rSec2[coroutine.trivial.awaitables]{Trivial awaitables} 530 | The header \tcode{} defines \tcode{suspend_never} and \tcode{suspend_always} as follows. 531 | \begin{codeblock} 532 | namespace std { 533 | namespace experimental { 534 | inline namespace coroutines_v1 { 535 | 536 | struct suspend_never { 537 | constexpr bool await_ready() const noexcept { return true; } 538 | constexpr void await_suspend(coroutine_handle<>) const noexcept {} 539 | constexpr void await_resume() const noexcept {} 540 | }; 541 | struct suspend_always { 542 | constexpr bool await_ready() const noexcept { return false; } 543 | constexpr void await_suspend(coroutine_handle<>) const noexcept {} 544 | constexpr void await_resume() const noexcept {} 545 | }; 546 | 547 | } // namespace coroutines_v1 548 | } // namespace experimental 549 | } // namespace std 550 | \end{codeblock} 551 | \end{quote} 552 | 553 | %\rSec2[coroutine.promise]{Coroutine promise requirements} 554 | % 555 | %\pnum 556 | %A user supplies the definition of the coroutine promise to implement 557 | %desired high-level semantics associated with a coroutines 558 | %discovered via instantiation of class template \tcode{coroutine_traits}. 559 | %The following tables describe the requirements on 560 | %coroutine promise types. 561 | % 562 | %%\pnum 563 | %%The template struct \tcode{allocator_traits}~(\ref{allocator.traits}) supplies 564 | %%a uniform interface to all allocator types. 565 | %%Table~\ref{tab:desc.var.def} describes the types manipulated 566 | %%through allocators. Table~\ref{tab:utilities.allocator.requirements} 567 | %%describes the requirements on allocator types 568 | %%and thus on types used to instantiate \tcode{allocator_traits}. A requirement 569 | %%is optional if the last column of 570 | %Table~\ref{tab:utilities.allocator.requirements} specifies a default for a 571 | %%given expression. Within the standard library \tcode{allocator_traits} 572 | %%template, an optional requirement that is not supplied by an allocator is 573 | %%replaced by the specified default expression. A user specialization of 574 | %%\tcode{allocator_traits} may provide different defaults and may provide 575 | %%defaults for different requirements than the primary template. Within 576 | %%Tables~\ref{tab:desc.var.def} and~\ref{tab:utilities.allocator.requirements}, 577 | %%the use of \tcode{move} and \tcode{forward} always refers to \tcode{std::move} 578 | %%and \tcode{std::forward}, respectively. 579 | % 580 | %\begin{libreqtab2} 581 | % {Descriptive variable definitions} 582 | % {tab:desc.var.def} 583 | % \\ \topline 584 | % \lhdr{Variable} & \rhdr{Definition} \\ \capsep 585 | % \endfirsthead 586 | % \continuedcaption\\ 587 | % \hline 588 | % \lhdr{Variable} & \rhdr{Definition} \\ \capsep 589 | % \endhead 590 | % \tcode{Promise} & a coroutine promise type \\ \rowsep 591 | % \tcode{p} & a value of type \tcode{Promise} \\ \rowsep 592 | % \tcode{e} & a value of \tcode{exception_ptr} type \\ \rowsep 593 | % \tcode{h} & a value of \tcode{coroutine_handle

} type \\ \rowsep 594 | % \tcode{v} & an \grammarterm{expression} or \grammarterm{braced-init-list} \\ \rowsep 595 | %\end{libreqtab2} 596 | % 597 | %\indextext{requirements!\idxcode{CoroutinePromise}}% 598 | %\begin{concepttable}{\tcode{CoroutinePromise} requirements}{CoroutinePromise} 599 | % {p{1.6in}p{4.15in}} 600 | % \topline 601 | % Expression & Note \\ \capsep 602 | % \tcode{Promise\{\}} & Construct an object of type \tcode{Promise}\\ \rowsep 603 | % \tcode{p.get_return_object()} & 604 | %The \tcode{get_return_object} is invoked by the coroutine to construct the 605 | %return object prior to reaching the first suspend-resume point, 606 | %a \tcode{return} statement, or flowing off the end of the function. 607 | % \\ \rowsep 608 | % \tcode{Promise::get_return_object_on_allocation_failure()} & 609 | % \textit{(Optional)} The \tcode{get_return_object_on_allocation_failure} is invoked by the coroutine to construct the 610 | % return object if allocation of the coroutine state failed. 611 | % \\ \rowsep 612 | % \tcode{p.return_value(v)} & 613 | %%If present, an enclosing coroutine supports an 614 | %%eventual value of a type that \tcode{v} can be converted to. 615 | % 616 | %\textit{(Optional)} Invoked by 617 | %a coroutine when 618 | %a \tcode{return} statement with an operand 619 | %is encountered in a coroutine as described in (\ref{stmt.return.coroutine}). 620 | %%If a promise type does not satisfy this requirement, the presence of 621 | %%a \tcode{coreturn} statement 622 | %%with an \grammarterm{expression} 623 | %%or a \grammarterm{braced-init-list} 624 | %%statement in the body results in a compile time error. 625 | % \\ \rowsep 626 | % \tcode{p.return_void()} & 627 | %%If present, an enclosing coroutine supports an eventual value of type \tcode{void}. 628 | %\textit{(Optional)} Invoked when 629 | %a \tcode{return} statement is encountered as described in (\ref{stmt.return.coroutine}). 630 | % \\ \rowsep 631 | % \tcode{p.set_exception(e)} & 632 | %\textit{(Optional)} If present, the \tcode{set_exception} is invoked by a coroutine when an 633 | %unhandled exception occurs within a \grammarterm{function-body} of the coroutine. 634 | %If the promise does not provide \tcode{set_exception}, an unhandled exception 635 | %will propagate from the coroutine normally. 636 | %\\ \rowsep 637 | % \tcode{p.yield_value(v)} & 638 | %\textit{(Optional)} The \tcode{yield_value} is invoked 639 | % when \tcode{co_yield} statement is 640 | % encountered in the coroutine. If 641 | % promise does not define \tcode{yield_value}, \tcode{co_yield} 642 | % statement shall not appear in the coroutine body. 643 | % \\ \rowsep 644 | % \tcode{p.initial_suspend()} & 645 | %A coroutine invokes \tcode{p.initial_suspend()} to obtain awaitable for \textit{initial suspend point} (\ref{dcl.fct.def.coroutine}). 646 | % \\ \rowsep 647 | % \tcode{p.final_suspend()} & 648 | %A coroutine invokes \tcode{p.final_suspend()} to obtain awaitable for \textit{final suspend point} (\ref{dcl.fct.def.coroutine}). 649 | %\\ 650 | %\end{concepttable} 651 | % 652 | %\pagebreak 653 | %\pnum 654 | %\enterexample 655 | %This example illustrates full implementation 656 | %of a promise type for a simple generator. 657 | %\begin{codeblock} 658 | % #include 659 | % #include 660 | % 661 | % struct generator { 662 | % struct promise_type { 663 | % int current_value; 664 | % auto get_return_object() { return generator{*this}; } 665 | % auto initial_suspend() { return std::experimental::suspend_always{}; } 666 | % auto final_suspend() { return std::experimental::suspend_always{}; } 667 | % auto yield_value(int value) { 668 | % current_value = value; 669 | % return std::experimental::suspend_always{}; 670 | % } 671 | % }; 672 | % 673 | % bool move_next() { 674 | % coro.resume(); 675 | % return !coro.done(); 676 | % } 677 | % 678 | % int current_value() { return coro.promise().current_value; } 679 | % 680 | % ~generator() { coro.destroy(); } 681 | % private: 682 | % using handle = std::experimental::coroutine_handle; 683 | % explicit generator(promise_type& myPromise): coro(handle::from_promise(myPromise)) {} 684 | % handle coro; 685 | % }; 686 | % 687 | % generator f() { 688 | % co_yield 1; 689 | % co_yield 2; 690 | % } 691 | % 692 | % int main() { 693 | % auto g = f(); 694 | % while (g.move_next()) std::cout << g.current_value() << std::endl; 695 | % } 696 | % 697 | %\end{codeblock} 698 | %\exitexample 699 | % 700 | %\end{quote} 701 | -------------------------------------------------------------------------------- /Coroutines/tables.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = std.tex 2 | % Definitions of table environments 3 | 4 | %%-------------------------------------------------- 5 | %% Table environments 6 | 7 | % Set parameters for floating tables 8 | \setcounter{totalnumber}{10} 9 | 10 | % Base definitions for tables 11 | \newenvironment{TableBase} 12 | { 13 | \renewcommand{\tcode}[1]{{\CodeStylex{##1}}} 14 | \newcommand{\topline}{\hline} 15 | \newcommand{\capsep}{\hline\hline} 16 | \newcommand{\rowsep}{\hline} 17 | \newcommand{\bottomline}{\hline} 18 | 19 | %% vertical alignment 20 | \newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{##1}} % move argument up half a row 21 | 22 | %% header helpers 23 | \newcommand{\hdstyle}[1]{\textbf{##1}} % set header style 24 | \newcommand{\Head}[3]{\multicolumn{##1}{##2}{\hdstyle{##3}}} % add title spanning multiple columns 25 | \newcommand{\lhdrx}[2]{\Head{##1}{|c}{##2}} % set header for left column spanning #1 columns 26 | \newcommand{\chdrx}[2]{\Head{##1}{c}{##2}} % set header for center column spanning #1 columns 27 | \newcommand{\rhdrx}[2]{\Head{##1}{c|}{##2}} % set header for right column spanning #1 columns 28 | \newcommand{\ohdrx}[2]{\Head{##1}{|c|}{##2}} % set header for only column spanning #1 columns 29 | \newcommand{\lhdr}[1]{\lhdrx{1}{##1}} % set header for single left column 30 | \newcommand{\chdr}[1]{\chdrx{1}{##1}} % set header for single center column 31 | \newcommand{\rhdr}[1]{\rhdrx{1}{##1}} % set header for single right column 32 | \newcommand{\ohdr}[1]{\ohdrx{1}{##1}} 33 | \newcommand{\br}{\hfill\break} % force newline within table entry 34 | 35 | %% column styles 36 | \newcolumntype{x}[1]{>{\raggedright\let\\=\tabularnewline}p{##1}} % word-wrapped ragged-right 37 | % column, width specified by #1 38 | % \newcolumntype{m}[1]{>{\CodeStyle}l{##1}} % variable width column, all entries in CodeStyle 39 | \newcolumntype{m}[1]{l{##1}} % variable width column, all entries in CodeStyle 40 | 41 | % do not number bullets within tables 42 | \renewcommand{\labelitemi}{---} 43 | \renewcommand{\labelitemii}{---} 44 | \renewcommand{\labelitemiii}{---} 45 | \renewcommand{\labelitemiv}{---} 46 | } 47 | { 48 | } 49 | 50 | % General Usage: TITLE is the title of the table, XREF is the 51 | % cross-reference for the table. LAYOUT is a sequence of column 52 | % type specifiers (e.g. cp{1.0}c), without '|' for the left edge 53 | % or right edge. 54 | 55 | % usage: \begin{floattablebase}{TITLE}{XREF}{COLUMNS}{PLACEMENT} 56 | % produces floating table, location determined within limits 57 | % by LaTeX. 58 | \newenvironment{floattablebase}[4] 59 | { 60 | \begin{TableBase} 61 | \begin{table}[#4] 62 | \caption{\label{#2}#1} 63 | \begin{center} 64 | \begin{tabular}{|#3|} 65 | } 66 | { 67 | \bottomline 68 | \end{tabular} 69 | \end{center} 70 | \end{table} 71 | \end{TableBase} 72 | } 73 | 74 | % usage: \begin{floattable}{TITLE}{XREF}{COLUMNS} 75 | % produces floating table, location determined within limits 76 | % by LaTeX. 77 | \newenvironment{floattable}[3] 78 | { 79 | \begin{floattablebase}{#1}{#2}{#3}{htbp} 80 | } 81 | { 82 | \end{floattablebase} 83 | } 84 | 85 | % usage: \begin{tokentable}{TITLE}{XREF}{HDR1}{HDR2} 86 | % produces six-column table used for lists of replacement tokens; 87 | % the columns are in pairs -- left-hand column has header HDR1, 88 | % right hand column has header HDR2; pairs of columns are separated 89 | % by vertical lines. Used in "trigraph sequences" table in standard. 90 | \newenvironment{tokentable}[4] 91 | { 92 | \begin{floattablebase}{#1}{#2}{cc|cc|cc}{htbp} 93 | \topline 94 | #3 & #4 & 95 | #3 & #4 & 96 | #3 & #4 \\ \capsep 97 | } 98 | { 99 | \end{floattablebase} 100 | } 101 | 102 | % usage: \begin{libsumtabbase}{TITLE}{XREF}{HDR1}{HDR2} 103 | % produces three-column table with column headers HDR1 and HDR2. 104 | % Used in "Library Categories" table in standard, and used as 105 | % base for other library summary tables. 106 | \newenvironment{libsumtabbase}[4] 107 | { 108 | \begin{floattable}{#1}{#2}{lll} 109 | \topline 110 | \lhdrx{2}{#3} & \hdstyle{#4} \\ \capsep 111 | } 112 | { 113 | \end{floattable} 114 | } 115 | 116 | % usage: \begin{libsumtab}{TITLE}{XREF} 117 | % produces three-column table with column headers "Subclause" and "Header(s)". 118 | % Used in "C++ Headers for Freestanding Implementations" table in standard. 119 | \newenvironment{libsumtab}[2] 120 | { 121 | \begin{libsumtabbase}{#1}{#2}{Subclause}{Header(s)} 122 | } 123 | { 124 | \end{libsumtabbase} 125 | } 126 | 127 | % usage: \begin{LibSynTab}{CAPTION}{TITLE}{XREF}{COUNT}{LAYOUT} 128 | % produces table with COUNT columns. Used as base for 129 | % C library description tables 130 | \newcounter{LibSynTabCols} 131 | \newcounter{LibSynTabWd} 132 | \newenvironment{LibSynTabBase}[5] 133 | { 134 | \setcounter{LibSynTabCols}{#4} 135 | \setcounter{LibSynTabWd}{#4} 136 | \addtocounter{LibSynTabWd}{-1} 137 | \newcommand{\centry}[1]{\textbf{##1}:} 138 | \newcommand{\macro}{\centry{Macro}} 139 | \newcommand{\macros}{\centry{Macros}} 140 | \newcommand{\function}{\centry{Function}} 141 | \newcommand{\functions}{\centry{Functions}} 142 | \newcommand{\mfunctions}{\centry{Math Functions}} 143 | \newcommand{\cfunctions}{\centry{Classification/comparison Functions}} 144 | \newcommand{\type}{\centry{Type}} 145 | \newcommand{\types}{\centry{Types}} 146 | \newcommand{\values}{\centry{Values}} 147 | \newcommand{\struct}{\centry{Struct}} 148 | \newcommand{\cspan}[1]{\multicolumn{\value{LibSynTabCols}}{|l|}{##1}} 149 | \begin{floattable}{#1 \tcode{<#2>} synopsis}{#3} 150 | {#5} 151 | \topline 152 | \lhdr{Type} & \rhdrx{\value{LibSynTabWd}}{Name(s)} \\ \capsep 153 | } 154 | { 155 | \end{floattable} 156 | } 157 | 158 | % usage: \begin{LibSynTab}{TITLE}{XREF}{COUNT}{LAYOUT} 159 | % produces table with COUNT columns. Used as base for description tables 160 | % for C library 161 | \newenvironment{LibSynTab}[4] 162 | { 163 | \begin{LibSynTabBase}{Header}{#1}{#2}{#3}{#4} 164 | } 165 | { 166 | \end{LibSynTabBase} 167 | } 168 | 169 | % usage: \begin{LibSynTabAdd}{TITLE}{XREF}{COUNT}{LAYOUT} 170 | % produces table with COUNT columns. Used as base for description tables 171 | % for additions to C library 172 | \newenvironment{LibSynTabAdd}[4] 173 | { 174 | \begin{LibSynTabBase}{Additions to header}{#1}{#2}{#3}{#4} 175 | } 176 | { 177 | \end{LibSynTabBase} 178 | } 179 | 180 | % usage: \begin{libsyntabN}{TITLE}{XREF} 181 | % \begin{libsyntabaddN}{TITLE}{XREF} 182 | % produces a table with N columns for C library description tables 183 | \newenvironment{libsyntab2}[2] 184 | { 185 | \begin{LibSynTab}{#1}{#2}{2}{ll} 186 | } 187 | { 188 | \end{LibSynTab} 189 | } 190 | 191 | \newenvironment{libsyntab3}[2] 192 | { 193 | \begin{LibSynTab}{#1}{#2}{3}{lll} 194 | } 195 | { 196 | \end{LibSynTab} 197 | } 198 | 199 | \newenvironment{libsyntab4}[2] 200 | { 201 | \begin{LibSynTab}{#1}{#2}{4}{llll} 202 | } 203 | { 204 | \end{LibSynTab} 205 | } 206 | 207 | \newenvironment{libsyntab5}[2] 208 | { 209 | \begin{LibSynTab}{#1}{#2}{5}{lllll} 210 | } 211 | { 212 | \end{LibSynTab} 213 | } 214 | 215 | \newenvironment{libsyntab6}[2] 216 | { 217 | \begin{LibSynTab}{#1}{#2}{6}{llllll} 218 | } 219 | { 220 | \end{LibSynTab} 221 | } 222 | 223 | \newenvironment{libsyntabadd2}[2] 224 | { 225 | \begin{LibSynTabAdd}{#1}{#2}{2}{ll} 226 | } 227 | { 228 | \end{LibSynTabAdd} 229 | } 230 | 231 | \newenvironment{libsyntabadd3}[2] 232 | { 233 | \begin{LibSynTabAdd}{#1}{#2}{3}{lll} 234 | } 235 | { 236 | \end{LibSynTabAdd} 237 | } 238 | 239 | \newenvironment{libsyntabadd4}[2] 240 | { 241 | \begin{LibSynTabAdd}{#1}{#2}{4}{llll} 242 | } 243 | { 244 | \end{LibSynTabAdd} 245 | } 246 | 247 | \newenvironment{libsyntabadd5}[2] 248 | { 249 | \begin{LibSynTabAdd}{#1}{#2}{5}{lllll} 250 | } 251 | { 252 | \end{LibSynTabAdd} 253 | } 254 | 255 | \newenvironment{libsyntabadd6}[2] 256 | { 257 | \begin{LibSynTabAdd}{#1}{#2}{6}{llllll} 258 | } 259 | { 260 | \end{LibSynTabAdd} 261 | } 262 | 263 | % usage: \begin{libsyntabfN}{TITLE}{XREF} 264 | % produces a fixed width table with N columns for C library description tables 265 | \newenvironment{libsyntabf2}[2] 266 | { 267 | \begin{LibSynTab}{#1}{#2}{2}{p{1in}p{4in}} 268 | } 269 | { 270 | \end{LibSynTab} 271 | } 272 | 273 | \newenvironment{libsyntabf3}[2] 274 | { 275 | \begin{LibSynTab}{#1}{#2}{3}{p{1in}p{.9in}p{2.9in}} 276 | } 277 | { 278 | \end{LibSynTab} 279 | } 280 | 281 | \newenvironment{libsyntabf5}[2] 282 | { 283 | \begin{LibSynTab}{#1}{#2}{5}{p{.9in}p{.9in}p{.9in}p{.9in}p{.9in}} 284 | } 285 | { 286 | \end{LibSynTab} 287 | } 288 | 289 | \newenvironment{libsyntabf4}[2] 290 | { 291 | \begin{LibSynTab}{#1}{#2}{4}{p{1in}p{.9in}p{.9in}p{1.8in}} 292 | } 293 | { 294 | \end{LibSynTab} 295 | } 296 | 297 | % usage: \begin{concepttable}{TITLE}{TAG}{LAYOUT} 298 | % produces table at current location 299 | \newenvironment{concepttable}[3] 300 | { 301 | \begin{TableBase} 302 | \begin{table}[!htb] 303 | \caption[#1]{\label{tab:#2}\label{#2}#1 \textbf{[#2]}} 304 | \begin{center} 305 | \begin{tabular}{|#3|} 306 | } 307 | { 308 | \bottomline 309 | \end{tabular} 310 | \end{center} 311 | \end{table} 312 | \end{TableBase} 313 | } 314 | 315 | % usage: \begin{simpletypetable}{TITLE}{TAG}{LAYOUT} 316 | % produces table at current location 317 | \newenvironment{simpletypetable}[3] 318 | { 319 | \begin{TableBase} 320 | \begin{table}[!htb] 321 | \caption{#1}\label{#2} 322 | \begin{center} 323 | \begin{tabular}{|#3|} 324 | } 325 | { 326 | \bottomline 327 | \end{tabular} 328 | \end{center} 329 | \end{table} 330 | \end{TableBase} 331 | } 332 | 333 | % usage: \begin{LongTable}{TITLE}{XREF}{LAYOUT} 334 | % produces table that handles page breaks sensibly. 335 | \newenvironment{LongTable}[3] 336 | { 337 | \newcommand{\continuedcaption}{\caption[]{#1 (continued)}} 338 | \begin{TableBase} 339 | \begin{longtable} 340 | {|#3|}\caption{#1}\label{#2} 341 | } 342 | { 343 | \bottomline 344 | \end{longtable} 345 | \end{TableBase} 346 | } 347 | 348 | % usage: \begin{twocol}{TITLE}{XREF} 349 | % produces a two-column breakable table. Used in 350 | % "simple-type-specifiers and the types they specify" in the standard. 351 | \newenvironment{twocol}[2] 352 | { 353 | \begin{concepttable} 354 | {#1}{#2} 355 | {ll} 356 | } 357 | { 358 | \end{LongTable} 359 | } 360 | 361 | % usage: \begin{libreqtabN}{TITLE}{XREF} 362 | % produces an N-column breakable table. Used in 363 | % most of the library Clauses for requirements tables. 364 | % Example at "Position type requirements" in the standard. 365 | 366 | \newenvironment{libreqtab1}[2] 367 | { 368 | \begin{LongTable} 369 | {#1}{#2} 370 | {x{.55\hsize}} 371 | } 372 | { 373 | \end{LongTable} 374 | } 375 | 376 | \newenvironment{libreqtab2}[2] 377 | { 378 | \begin{LongTable} 379 | {#1}{#2} 380 | {lx{.55\hsize}} 381 | } 382 | { 383 | \end{LongTable} 384 | } 385 | 386 | \newenvironment{libreqtab2a}[2] 387 | { 388 | \begin{LongTable} 389 | {#1}{#2} 390 | {x{.30\hsize}x{.68\hsize}} 391 | } 392 | { 393 | \end{LongTable} 394 | } 395 | 396 | \newenvironment{libreqtab3}[2] 397 | { 398 | \begin{LongTable} 399 | {#1}{#2} 400 | {x{.28\hsize}x{.18\hsize}x{.43\hsize}} 401 | } 402 | { 403 | \end{LongTable} 404 | } 405 | 406 | \newenvironment{libreqtab3a}[2] 407 | { 408 | \begin{LongTable} 409 | {#1}{#2} 410 | {x{.28\hsize}x{.33\hsize}x{.29\hsize}} 411 | } 412 | { 413 | \end{LongTable} 414 | } 415 | 416 | \newenvironment{libreqtab3b}[2] 417 | { 418 | \begin{LongTable} 419 | {#1}{#2} 420 | {x{.40\hsize}x{.25\hsize}x{.25\hsize}} 421 | } 422 | { 423 | \end{LongTable} 424 | } 425 | 426 | \newenvironment{libreqtab3c}[2] 427 | { 428 | \begin{LongTable} 429 | {#1}{#2} 430 | {x{.30\hsize}x{.25\hsize}x{.35\hsize}} 431 | } 432 | { 433 | \end{LongTable} 434 | } 435 | 436 | \newenvironment{libreqtab3d}[2] 437 | { 438 | \begin{LongTable} 439 | {#1}{#2} 440 | {x{.32\hsize}x{.27\hsize}x{.36\hsize}} 441 | } 442 | { 443 | \end{LongTable} 444 | } 445 | 446 | \newenvironment{libreqtab3e}[2] 447 | { 448 | \begin{LongTable} 449 | {#1}{#2} 450 | {x{.38\hsize}x{.27\hsize}x{.25\hsize}} 451 | } 452 | { 453 | \end{LongTable} 454 | } 455 | 456 | \newenvironment{libreqtab3f}[2] 457 | { 458 | \begin{LongTable} 459 | {#1}{#2} 460 | {x{.40\hsize}x{.22\hsize}x{.31\hsize}} 461 | } 462 | { 463 | \end{LongTable} 464 | } 465 | 466 | \newenvironment{libreqtab4}[2] 467 | { 468 | \begin{LongTable} 469 | {#1}{#2} 470 | } 471 | { 472 | \end{LongTable} 473 | } 474 | 475 | \newenvironment{libreqtab4a}[2] 476 | { 477 | \begin{LongTable} 478 | {#1}{#2} 479 | {x{.14\hsize}x{.30\hsize}x{.30\hsize}x{.14\hsize}} 480 | } 481 | { 482 | \end{LongTable} 483 | } 484 | 485 | \newenvironment{libreqtab4b}[2] 486 | { 487 | \begin{LongTable} 488 | {#1}{#2} 489 | {x{.13\hsize}x{.15\hsize}x{.29\hsize}x{.27\hsize}} 490 | } 491 | { 492 | \end{LongTable} 493 | } 494 | 495 | \newenvironment{libreqtab4c}[2] 496 | { 497 | \begin{LongTable} 498 | {#1}{#2} 499 | {x{.16\hsize}x{.21\hsize}x{.21\hsize}x{.30\hsize}} 500 | } 501 | { 502 | \end{LongTable} 503 | } 504 | 505 | \newenvironment{libreqtab4d}[2] 506 | { 507 | \begin{LongTable} 508 | {#1}{#2} 509 | {x{.22\hsize}x{.22\hsize}x{.30\hsize}x{.15\hsize}} 510 | } 511 | { 512 | \end{LongTable} 513 | } 514 | 515 | \newenvironment{libreqtab5}[2] 516 | { 517 | \begin{LongTable} 518 | {#1}{#2} 519 | {x{.14\hsize}x{.14\hsize}x{.20\hsize}x{.20\hsize}x{.14\hsize}} 520 | } 521 | { 522 | \end{LongTable} 523 | } 524 | 525 | % usage: \begin{libtab2}{TITLE}{XREF}{LAYOUT}{HDR1}{HDR2} 526 | % produces two-column table with column headers HDR1 and HDR2. 527 | % Used in "seekoff positioning" in the standard. 528 | \newenvironment{libtab2}[5] 529 | { 530 | \begin{floattable} 531 | {#1}{#2}{#3} 532 | \topline 533 | \lhdr{#4} & \rhdr{#5} \\ \capsep 534 | } 535 | { 536 | \end{floattable} 537 | } 538 | 539 | % usage: \begin{longlibtab2}{TITLE}{XREF}{LAYOUT}{HDR1}{HDR2} 540 | % produces two-column table with column headers HDR1 and HDR2. 541 | \newenvironment{longlibtab2}[5] 542 | { 543 | \begin{LongTable}{#1}{#2}{#3} 544 | \\ \topline 545 | \lhdr{#4} & \rhdr{#5} \\ \capsep 546 | \endfirsthead 547 | \continuedcaption\\ 548 | \topline 549 | \lhdr{#4} & \rhdr{#5} \\ \capsep 550 | \endhead 551 | } 552 | { 553 | \end{LongTable} 554 | } 555 | 556 | % usage: \begin{LibEffTab}{TITLE}{XREF}{HDR2}{WD2} 557 | % produces a two-column table with left column header "Element" 558 | % and right column header HDR2, right column word-wrapped with 559 | % width specified by WD2. 560 | \newenvironment{LibEffTab}[4] 561 | { 562 | \begin{libtab2}{#1}{#2}{lp{#4}}{Element}{#3} 563 | } 564 | { 565 | \end{libtab2} 566 | } 567 | 568 | % Same as LibEffTab except that it uses a long table. 569 | \newenvironment{longLibEffTab}[4] 570 | { 571 | \begin{longlibtab2}{#1}{#2}{lp{#4}}{Element}{#3} 572 | } 573 | { 574 | \end{longlibtab2} 575 | } 576 | 577 | % usage: \begin{libefftab}{TITLE}{XREF} 578 | % produces a two-column effects table with right column 579 | % header "Effect(s) if set", width 4.5 in. Used in "fmtflags effects" 580 | % table in standard. 581 | \newenvironment{libefftab}[2] 582 | { 583 | \begin{LibEffTab}{#1}{#2}{Effect(s) if set}{4.5in} 584 | } 585 | { 586 | \end{LibEffTab} 587 | } 588 | 589 | % Same as libefftab except that it uses a long table. 590 | \newenvironment{longlibefftab}[2] 591 | { 592 | \begin{longLibEffTab}{#1}{#2}{Effect(s) if set}{4.5in} 593 | } 594 | { 595 | \end{longLibEffTab} 596 | } 597 | 598 | % usage: \begin{libefftabmean}{TITLE}{XREF} 599 | % produces a two-column effects table with right column 600 | % header "Meaning", width 4.5 in. Used in "seekdir effects" 601 | % table in standard. 602 | \newenvironment{libefftabmean}[2] 603 | { 604 | \begin{LibEffTab}{#1}{#2}{Meaning}{4.5in} 605 | } 606 | { 607 | \end{LibEffTab} 608 | } 609 | 610 | % Same as libefftabmean except that it uses a long table. 611 | \newenvironment{longlibefftabmean}[2] 612 | { 613 | \begin{longLibEffTab}{#1}{#2}{Meaning}{4.5in} 614 | } 615 | { 616 | \end{longLibEffTab} 617 | } 618 | 619 | % usage: \begin{libefftabvalue}{TITLE}{XREF} 620 | % produces a two-column effects table with right column 621 | % header "Value", width 3 in. Used in "basic_ios::init() effects" 622 | % table in standard. 623 | \newenvironment{libefftabvalue}[2] 624 | { 625 | \begin{LibEffTab}{#1}{#2}{Value}{3in} 626 | } 627 | { 628 | \end{LibEffTab} 629 | } 630 | 631 | % Same as libefftabvalue except that it uses a long table and a 632 | % slightly wider column. 633 | \newenvironment{longlibefftabvalue}[2] 634 | { 635 | \begin{longLibEffTab}{#1}{#2}{Value}{3.5in} 636 | } 637 | { 638 | \end{longLibEffTab} 639 | } 640 | 641 | % usage: \begin{liberrtab}{TITLE}{XREF} produces a two-column table 642 | % with left column header ``Value'' and right header "Error 643 | % condition", width 4.5 in. Used in regex Clause in the TR. 644 | 645 | \newenvironment{liberrtab}[2] 646 | { 647 | \begin{libtab2}{#1}{#2}{lp{4.5in}}{Value}{Error condition} 648 | } 649 | { 650 | \end{libtab2} 651 | } 652 | 653 | % Like liberrtab except that it uses a long table. 654 | \newenvironment{longliberrtab}[2] 655 | { 656 | \begin{longlibtab2}{#1}{#2}{lp{4.5in}}{Value}{Error condition} 657 | } 658 | { 659 | \end{longlibtab2} 660 | } 661 | -------------------------------------------------------------------------------- /Coroutines/threads.tex: -------------------------------------------------------------------------------- 1 | %\setcounter{chapter}{29} 2 | %\rSec0[thread]{Thread support library} 3 | % 4 | %\setcounter{section}{2} 5 | %\rSec1[thread.threads]{Threads} 6 | % 7 | %\setcounter{subsection}{1} 8 | %\rSec2[thread.thread.this]{Namespace \tcode{this_thread}} 9 | % 10 | %Rename \tcode{yield} 11 | %function to \tcode{yield_execution}. 12 | % 13 | %\begin{quote} 14 | %\begin{codeblock} 15 | %namespace std { 16 | % namespace this_thread { 17 | % thread::id get_id() noexcept; 18 | % 19 | % void yield@\added{_execution}@() noexcept; 20 | % template 21 | % void sleep_until(const chrono::time_point& abs_time); 22 | % template 23 | % void sleep_for(const chrono::duration& rel_time); 24 | % } 25 | %} 26 | %\end{codeblock} 27 | % 28 | %\indexlibrary{\idxcode{this_thread}!\idxcode{get_id}}% 29 | %\indexlibrary{\idxcode{get_id}!\idxcode{this_thread}}% 30 | %\begin{itemdecl} 31 | %thread::id this_thread::get_id() noexcept; 32 | %\end{itemdecl} 33 | % 34 | %\begin{itemdescr} 35 | %\pnum 36 | %\returns An object of type \tcode{thread::id} that uniquely identifies the current thread of 37 | %execution. No other thread of execution shall have this id and this thread of execution shall 38 | %always have this id. The object returned shall not compare equal to a default constructed 39 | %\tcode{thread::id}. 40 | %\end{itemdescr} 41 | % 42 | %\indexlibrary{\idxcode{this_thread}!\idxcode{yield\added{_execution}}}% 43 | %\indexlibrary{\idxcode{yield\added{_execution}}!\idxcode{this_thread}}% 44 | %\begin{itemdecl} 45 | %void this_thread::yield@\added{_execution}@() noexcept; 46 | %\end{itemdecl} 47 | % 48 | %\begin{itemdescr} 49 | %\pnum 50 | %\effects Offers the implementation the opportunity to reschedule. 51 | % 52 | %\pnum 53 | %\sync None. 54 | %\end{itemdescr} 55 | %\end{quote} -------------------------------------------------------------------------------- /r4/r3.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GorNishanov/coroutines-ts/5bca637a6dd29f719c9ec2409251f3f89d4aacb1/r4/r3.docx -------------------------------------------------------------------------------- /r4/r4.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GorNishanov/coroutines-ts/5bca637a6dd29f719c9ec2409251f3f89d4aacb1/r4/r4.docx --------------------------------------------------------------------------------