c++ now: c++ coroutines with boost::cobalt

This program uses boost::cobalt to manage c++ coroutines.

API Used:

  • boost::cobalt (See)
  • cobalt::promise
  • cobalt::generator
  • cobalt co_main

Utxcpp

Download nirtcpp source code:

nirtcpp-2.0.0.1-src.zip (md5)

#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;
}

Output:

6.25
=> 2.25
=> 3.75
=> 5.25
=> 6.75

Utxcpp

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.

Enter

Utxcpp Samples Driven

Utxcpp Samples Driven Docs

Enter

Nirtcpp

Nirtcpp is a graphics and game
engine forked irrlicht.

Enter

Logs

Logs - Record my c++ explorer

Enter

B2 Build

B2 is an easy to use and very
powerful cpp/c++ project
build system.

Enter

Utxcpp Install

Install b2 build, Install boostbook,
Install quickbook, Install Utxcpp

Enter