Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/coroutine/noop coroutine promise"

From cppreference.com
< cpp‎ | coroutine
(IMO this impl detail is not worth mentioning)
m (fmt)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{cpp/title|noop_coroutine_promise}}
 
{{cpp/title|noop_coroutine_promise}}
 
{{cpp/coroutine/navbar}}
 
{{cpp/coroutine/navbar}}
{{ddcl | header=coroutine | since=c++20 |
+
{{ddcl|header=coroutine|since=c++20|
 
struct noop_coroutine_promise {};
 
struct noop_coroutine_promise {};
 
}}
 
}}
Line 15: Line 15:
 
{{todo|more precise wording}}
 
{{todo|more precise wording}}
  
No-op coroutines can be started by {{lc|std::noop_coroutine}}, and controlled by the coroutine handle it returns. The returned coroutined handle is of type {{lc|std::noop_coroutine_handle}}, which is a synonym for {{c|std::coroutine_handle<std::noop_coroutine_promise>}}.
+
No-op coroutines can be started by {{lc|std::noop_coroutine}}, and controlled by the coroutine handle it returns. The returned coroutine handle is of type {{lc|std::noop_coroutine_handle}}, which is a synonym for {{c|std::coroutine_handle<std::noop_coroutine_promise>}}.
  
 
Some operations of a no-op coroutines are determined no-op at compile time through the type {{tt|std::noop_coroutine_handle}}.
 
Some operations of a no-op coroutines are determined no-op at compile time through the type {{tt|std::noop_coroutine_handle}}.
Line 26: Line 26:
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/coroutine/dsc noop_coroutine}}
+
{{dsc inc|cpp/coroutine/dsc noop_coroutine}}
{{dsc inc | cpp/coroutine/dsc noop_coroutine_handle}}
+
{{dsc inc|cpp/coroutine/dsc noop_coroutine_handle}}
 
{{dsc end}}
 
{{dsc end}}
  
{{langlinks|ja|zh}}
+
{{langlinks|es|ja|ru|zh}}

Latest revision as of 11:57, 5 November 2023

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Coroutine support
Coroutine traits
Coroutine handle
No-op coroutines
noop_coroutine_promise
(C++20)
Trivial awaitables
Range generators
(C++23)
 
Defined in header <coroutine>
struct noop_coroutine_promise {};
(since C++20)

noop_coroutine_promise is the promise type of no-op coroutines.

A no-op coroutine behaves as if it

  • does nothing other than the control flow of a coroutine, and
  • is suspended immediately after beginning and resumption, and
  • has a coroutine state such that destroying the state is no-op, and
  • never reaches its final suspended point if there is any std::coroutine_handle referring to it.

No-op coroutines can be started by std::noop_coroutine, and controlled by the coroutine handle it returns. The returned coroutine handle is of type std::noop_coroutine_handle, which is a synonym for std::coroutine_handle<std::noop_coroutine_promise>.

Some operations of a no-op coroutines are determined no-op at compile time through the type std::noop_coroutine_handle.

[edit] Example

[edit] See also

creates a coroutine handle that has no observable effects when resumed or destroyed
(function) [edit]
std::coroutine_handle<std::noop_coroutine_promise>, intended to refer to a no-op coroutine
(typedef) [edit]