Skip to content

Instantly share code, notes, and snippets.

#ifndef EXPERIMENTAL_SIMPLE_GENERATOR
# define EXPERIMENTAL_SIMPLE_GENERATOR
#include <experimental/coroutine>
namespace std::experimental {
template <typename T> struct generator {
struct promise_type {
T current_value;
suspend_always yield_value(T value) {
this->current_value = value;
@GorNishanov
GorNishanov / read_until_adapter
Created May 28, 2017 20:21
An example of an await adapter for async_read_until
template <typename SyncReadStream, typename DynamicBuffer>
auto async_read_until(SyncReadStream &s, DynamicBuffer &&buffers,
string delim) {
struct Awaiter {
SyncReadStream &s;
DynamicBuffer &&buffers;
string delim;
std::error_code ec;
size_t sz;
; Emulating cps call using LLVM Coroutines
; RUN: opt coro-cps.ll -O2 -enable-coroutines -S
define void @f(i32 %arg) {
entry:
%bar.ret.addr = alloca i32
%id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
%size = call i32 @llvm.coro.size.i32()
%alloc = call i8* @malloc(i32 %size)
%hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
@GorNishanov
GorNishanov / recursive_generator.h
Created March 15, 2017 16:03
recursive_generator implementation
#ifndef RECURSIVE_recursive_generator
#define RECURSIVE_recursive_generator
#include <experimental/coroutine>
// This class implements delegating (potentially recursive) recursive_generator.
// It supports two kind of yield expressions:
//
// co_yield V;
// co_yield G_of_T;
@GorNishanov
GorNishanov / LeanFuture.cpp
Last active October 6, 2016 14:42
CppCon 2016 Lean Future Example
#include <stdio.h>
#include <exception>
#include <experimental/coroutine>
#include <tuple>
#include <mutex>
#include <condition_variable>
#include <cstdlib>
struct monostate {};