wwa-coro 0.0.1
Yet Another C++20 Coroutine Library
sync_generator_adapter.h File Reference

Adapter for converting asynchronous generators to synchronous generators. More...

#include <cstddef>
#include <iterator>
#include <ranges>
#include <utility>
#include "async_generator.h"
#include "eager_task.h"
+ Include dependency graph for sync_generator_adapter.h:

Go to the source code of this file.

Classes

class  wwa::coro::sync_generator_adapter< Result >
 Adapter for converting asynchronous generators to synchronous generators. More...
 
struct  wwa::coro::sync_generator_adapter< Result >::iterator
 Iterator for the synchronous generator adapter. More...
 

Namespaces

namespace  wwa
 
namespace  wwa::coro
 Library namespace.
 

Functions

template<typename Result>
 wwa::coro::sync_generator_adapter (async_generator< Result >) -> sync_generator_adapter< Result >
 Deduction guide for sync_generator_adapter.
 

Detailed Description

Adapter for converting asynchronous generators to synchronous generators.

This header file defines the sync_generator_adapter class, which adapts an async_generator to provide a synchronous generator interface. This allows asynchronous generators to be used in contexts where synchronous iteration is required.

Example:

wwa::coro::async_generator<int> async_iota(int start = 0)
{
for (int i = start;; ++i) {
co_yield i;
}
}
wwa::coro::sync_generator_adapter sync_iota(async_iota(10));
for (const auto& n : sync_iota | std::views::take(5)) {
std::cout << n << "\n";
}

Definition in file sync_generator_adapter.h.