wwa-coro 0.0.1
Yet Another C++20 Coroutine Library
wwa::coro Namespace Reference

Library namespace. More...

Classes

class  async_generator
 An asynchronous generator that produces values of type Result. More...
class  bad_result_access
 Exception thrown when accessing a result that is not available. More...
class  bad_task
 Exception thrown when a coroutine task is invalid. More...
class  eager_task
 Eager coroutine. More...
class  iterator
 An input iterator that produces values of type Result. More...
class  promise_type
 An synchronous generator that produces values of type Result. More...
class  task
 A coroutine task. More...

Functions

 ~generator ()
 Destructor.
template<typename AsyncGenerator, typename Callable>
task< void > async_for_each (AsyncGenerator gen, Callable callable)
iterator begin ()
 Returns an iterator to the current item of the generator.
constexpr iterator end () const noexcept
 Returns a sentinel iterator that marks the end of the generator.
 generator () noexcept=default
 Default constructor.
 generator (generator &&other) noexcept
 Move constructor.
generatoroperator= (generator &&other) noexcept
 Move assignment operator.
template<typename Awaitable, typename... Args>
eager_task run_awaitable (Awaitable &&f, Args &&... args)
 Turns any awaitable into an eager fire-and-forget coroutine.

Detailed Description

Library namespace.

Function Documentation

◆ ~generator()

wwa::coro::~generator ( )

Destructor.

Destroys the generator and the coroutine handle.

Definition at line 349 of file generator.h.

◆ async_for_each()

template<typename AsyncGenerator, typename Callable>
task< void > wwa::coro::async_for_each ( AsyncGenerator gen,
Callable callable )

Definition at line 607 of file async_generator.h.

◆ begin()

iterator wwa::coro::begin ( )
nodiscard

Returns an iterator to the current item of the generator.

Returns a constant iterator to the current item of the generator.

This method returns an iterator to the current item of the generator. It is called begin() only to allow the generator to be used in range-based for loops or with ranges.

Because generators cannot be restarted, this method can be used to iterate over the generator:

auto gen = sync_first_n(5);
auto it = gen.begin();
auto end = gen.end();
do {
std::cout << *it << " ";
} while (gen.begin() != end);
Returns
Iterator to the current item.
See also
begin()
Returns
Constant iterator to the current item.

Definition at line 401 of file generator.h.

◆ end()

iterator wwa::coro::end ( ) const
nodiscardconstexprnoexcept

Returns a sentinel iterator that marks the end of the generator.

This method returns a sentinel iterator that marks the end of the generator. An attempt to dereference this iterator or iterate past it will result in an exception being thrown.

Definition at line 434 of file generator.h.

◆ generator() [1/2]

wwa::coro::generator ( )
defaultnoexcept

Default constructor.

Constructs an empty generator. This constructor is not really useful except for testing.

Examples
advance_with_begin.cpp, generator.cpp, and generator_iterator.cpp.

◆ generator() [2/2]

wwa::coro::generator ( generator && other)
noexcept

Move constructor.

Constructs a generator by moving the coroutine handle from another generator.

Parameters
otherThe other generator to move from.

Definition at line 339 of file generator.h.

◆ operator=()

generator & wwa::coro::operator= ( generator && other)
noexcept

Move assignment operator.

Assigns the contents of another generator to this generator by moving them.

Parameters
otherThe other generator to move.
Returns
Reference to this generator.

Definition at line 369 of file generator.h.

◆ run_awaitable()

template<typename Awaitable, typename... Args>
eager_task wwa::coro::run_awaitable ( Awaitable && f,
Args &&... args )

Turns any awaitable into an eager fire-and-forget coroutine.

This method template takes an awaitable callable and its arguments, invokes the callable with the provided arguments, and co_await's the result. It effectively runs the awaitable in a fire-and-forget manner.

Template Parameters
AwaitableThe type of the awaitable callable.
ArgsThe types of the arguments to be passed to the callable.
Parameters
fThe awaitable callable to be invoked.
argsThe arguments to be passed to the callable.
Returns
A fire-and-forget task.
Examples
run_awaitable.cpp, and task.cpp.

Definition at line 129 of file eager_task.h.