Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/coroutine/suspend never"

From cppreference.com
< cpp‎ | coroutine
m (See also)
m
 
Line 9: Line 9:
 
===Member functions===
 
===Member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc mem fun|await_ready|nolink=true|notes={{mark c++20}}|indicates that an await expression never suspends}}
+
{{dsc mem fun|await_ready|nolink=true|indicates that an await expression never suspends}}
{{dsc mem fun|await_suspend|nolink=true|notes={{mark c++20}}|no-op}}
+
{{dsc mem fun|await_suspend|nolink=true|no-op}}
{{dsc mem fun|await_resume|nolink=true|notes={{mark c++20}}|no-op}}
+
{{dsc mem fun|await_resume|nolink=true|no-op}}
 
{{dsc end}}
 
{{dsc end}}
  
 
{{member|{{small|std::suspend_never::}}await_ready|2=
 
{{member|{{small|std::suspend_never::}}await_ready|2=
{{ddcl|since=c++20|
+
{{ddcl|
 
constexpr bool await_ready() const noexcept { return true; }
 
constexpr bool await_ready() const noexcept { return true; }
 
}}
 
}}
Line 23: Line 23:
  
 
{{member|{{small|std::suspend_never::}}await_suspend|2=
 
{{member|{{small|std::suspend_never::}}await_suspend|2=
{{ddcl|since=c++20|
+
{{ddcl|
 
constexpr void await_suspend( std::coroutine_handle<> ) const noexcept {}
 
constexpr void await_suspend( std::coroutine_handle<> ) const noexcept {}
 
}}
 
}}
Line 31: Line 31:
  
 
{{member|{{small|std::suspend_never::}}await_resume|2=
 
{{member|{{small|std::suspend_never::}}await_resume|2=
{{ddcl|since=c++20|
+
{{ddcl|
 
constexpr void await_resume() const noexcept {}
 
constexpr void await_resume() const noexcept {}
 
}}
 
}}

Latest revision as of 13:55, 30 October 2024

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

suspend_never is an empty class which can be used to indicate that an await expression never suspends and does not produce a value.

Contents

[edit] Member functions

await_ready
indicates that an await expression never suspends
(public member function)
await_suspend
no-op
(public member function)
await_resume
no-op
(public member function)

std::suspend_never::await_ready

constexpr bool await_ready() const noexcept { return true; }

Always returns true, indicating that an await expression never suspends.

std::suspend_never::await_suspend

constexpr void await_suspend( std::coroutine_handle<> ) const noexcept {}

Does nothing.

std::suspend_never::await_resume

constexpr void await_resume() const noexcept {}

Does nothing. An await expression does not produce a value if suspend_never is used.

[edit] Example

[edit] See also

indicates that an await-expression should always suspend
(class) [edit]