https://cppfx.xyz
This program uses boost::cobalt to manage c++ coroutines.
#include <boost/cobalt.hpp> #include <iostream> #include <chrono> namespace cobalt = boost::cobalt; using std::chrono_literals::operator""s; class bob_box { public: virtual ~bob_box() = default; public: cobalt::promise<float> fn(float x) const { co_return x*x; } cobalt::generator<float> func(float x) const { float i = 1.5f; while (true) co_yield x*i++; } }; cobalt::main co_main(int argc, char * argv[]) { auto bob = bob_box{}; std::cout << co_await bob.fn(2.5f) << std::endl; // 6.25 auto start = std::chrono::system_clock::now(); auto rco = bob.func(1.5f); while (auto now = std::chrono::system_clock::now() < start + 2.7s && rco) { std::cout << "=> " << co_await rco << std::endl; std::this_thread::sleep_for(0.8s); } co_return 0; }
6.25 => 2.25 => 3.75 => 5.25 => 6.75
Utxcpp is an easy and simple to use c++ library that makes simple things simple. Utxcpp has some classes, templates and functions that can be used in sycl kernel.