Commit 048d2879 authored by Xavier Thompson's avatar Xavier Thompson

Add Makefile and test programs

parent 0ea78132
CXX=g++-11
CXXFLAGS=-g -O3 -fwhole-program -flto -Wall -Wextra -Werror -std=c++20 -fcoroutines -I.
LDLIBS=-ljemalloc
#include <task.hpp>
#include <cstdio>
using namespace typon;
task<int> add(int a, int b) {
co_return a + b;
}
task<int> loop(int n) {
int result = 0;
for (int i = 0; i < n; i++) {
result = result + co_await add(i, i+1);
}
co_return result;
}
int main() {
int result = loop(100000000).call();
printf("%d\n", result);
}
#include <task.hpp>
#include <cstdio>
using namespace typon;
task<int> fibo(int n) {
if (n < 2) {
co_return n;
}
int a = co_await fibo(n - 1);
int b = co_await fibo(n - 2);
co_return a + b;
}
int main() {
int result = fibo(40).call();
printf("%d\n", result);
}
#ifndef __ROOT_HPP__
#define __ROOT_HPP__
#include <coroutine>
namespace typon
{
struct root
{
struct promise_type;
std::coroutine_handle<promise_type> _coroutine;
struct promise_type
{
root get_return_object() noexcept
{
return { std::coroutine_handle<promise_type>::from_promise(*this) };
}
std::suspend_never initial_suspend() noexcept
{
return {};
}
std::suspend_never final_suspend() noexcept
{
return {};
}
void return_void() noexcept {}
void unhandled_exception() noexcept {}
};
};
}
#endif // __ROOT_HPP__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment