D++ (DPP)
C++ Discord API Bot Library
dpp::coroutine< R > Class Template Reference

Base type for a coroutine, starts on co_await. More...

#include <coro/coroutine.h>

+ Inheritance diagram for dpp::coroutine< R >:
+ Collaboration diagram for dpp::coroutine< R >:

Public Member Functions

 coroutine ()=default
 Default constructor, creates an empty coroutine. More...
 
 coroutine (const coroutine &)=delete
 Copy constructor is disabled. More...
 
 coroutine (coroutine &&other) noexcept
 Move constructor, grabs another coroutine's handle. More...
 
 ~coroutine ()
 Destructor, destroys the handle. More...
 
coroutineoperator= (const coroutine &)=delete
 Copy assignment is disabled. More...
 
coroutineoperator= (coroutine &&other) noexcept
 Move assignment, grabs another coroutine's handle. More...
 
bool await_ready () const
 First function called by the standard library when the coroutine is co_await-ed. More...
 
auto & operator co_await () &noexcept
 Suspend the caller until the coroutine completes. More...
 
const auto & operator co_await () const &noexcept
 Suspend the caller until the coroutine completes. More...
 
auto && operator co_await () &&noexcept
 Suspend the caller until the coroutine completes. More...
 

Friends

class detail::coroutine::coroutine_base< R >
 Internal use only base class containing common logic between coroutine<R> and coroutine<void>. It also serves to prevent await_suspend and await_resume from being used directly. More...
 

Detailed Description

template<typename R>
class dpp::coroutine< R >

Base type for a coroutine, starts on co_await.

Warning
- This feature is EXPERIMENTAL. The API may change at any time and there may be bugs. Please report any to GitHub Issues or to our Discord Server.
- Using co_await on this object more than once is undefined behavior.
Template Parameters
RReturn type of the coroutine. Can be void, or a complete object that supports move construction and move assignment.

Constructor & Destructor Documentation

◆ coroutine() [1/3]

template<typename R >
dpp::coroutine< R >::coroutine ( )
default

Default constructor, creates an empty coroutine.

◆ coroutine() [2/3]

template<typename R >
dpp::coroutine< R >::coroutine ( const coroutine< R > &  )
delete

Copy constructor is disabled.

◆ coroutine() [3/3]

template<typename R >
dpp::coroutine< R >::coroutine ( coroutine< R > &&  other)
noexcept

Move constructor, grabs another coroutine's handle.

Parameters
otherCoroutine to move the handle from

◆ ~coroutine()

template<typename R >
dpp::coroutine< R >::~coroutine ( )

Destructor, destroys the handle.

Member Function Documentation

◆ await_ready()

template<typename R >
bool dpp::coroutine< R >::await_ready ( ) const

First function called by the standard library when the coroutine is co_await-ed.

Remarks
Do not call this manually, use the co_await keyword instead.
Exceptions
invalid_operation_exceptionif the coroutine is empty or finished.
Returns
bool Whether the coroutine is done

◆ operator co_await() [1/3]

template<typename R >
auto && dpp::coroutine< R >::operator co_await ( ) &&
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as an rvalue reference.

◆ operator co_await() [2/3]

template<typename R >
auto & dpp::coroutine< R >::operator co_await ( ) &
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as a reference.

◆ operator co_await() [3/3]

template<typename R >
const auto & dpp::coroutine< R >::operator co_await ( ) const &
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as a const reference.

◆ operator=() [1/2]

template<typename R >
coroutine & dpp::coroutine< R >::operator= ( const coroutine< R > &  )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

template<typename R >
coroutine & dpp::coroutine< R >::operator= ( coroutine< R > &&  other)
noexcept

Move assignment, grabs another coroutine's handle.

Parameters
otherCoroutine to move the handle from

Friends And Related Function Documentation

◆ detail::coroutine::coroutine_base< R >

template<typename R >
friend class detail::coroutine::coroutine_base< R >
friend

Internal use only base class containing common logic between coroutine<R> and coroutine<void>. It also serves to prevent await_suspend and await_resume from being used directly.

Warning
For internal use only, do not use.
See also
operator co_await()
D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0