efficiency

My first coroutine--Kirit Sælensminde

What's the point of coroutines?

My first coroutine

by Kirit Sælensminde

From the article:

There are more and more examples coming out of how to convert things like the use of futures into coroutines, and you may be forgiven for thinking that there is also some magic that happens in boost::future or std::future that lets this work, but that's not the case.

In C++ a coroutine is any function that contains one of the coroutine keywords in its body, that is any of co_return, co_yield or co_await.

What we're going to do is to write a very basic mechanism that allows us to use co_return to return a value from a coroutine. Coroutines are really a generalisation of a function call, and what this is going to allow us to do is to treat a coroutine as a function call. If we can't do this then we don't stand much chance of doing anything more interesting with them, but it will give us a good starter on how the machinery works...

How C++ coroutines work--Kirit Sælensminde

What's the point of coroutines?

How C++ coroutines work

by Kirit Sælensminde

From the article:

If you look at coroutines in other language, JavaScript or Python for example, you'll see that the language documents how the coroutines work. How you can use co_yield and co_await etc. (however they're spelled) and what the language does for you with them. This is all very useful, and lets you do a lot of cool things with them, but always within the confines of what the language runtime allows.

In C++ they're quite different. The compiler provides a scaffolding on which you can decide how things work. This means that C++ doesn't provide generators, but it provides you a way to write a ton of different generators that work in different ways depending on your needs.

This is what this series of articles is going to be about. Not how to use or write coroutines that work according to some pre-established pattern, but how the underlying machinery allows you to customise the way that the coroutines work...

C++ Weekly Episode 70: C++ IIFE in quick-bench.com—Jason Turner

Episode 70 of C++ Weekly.

C++ IIFE in quick-bench.com

by Jason Turner

About the show:

We are commonly taught to const everything that we can in C++. One way to accomplish this goal in the post-C++11 world is to use a immediately invoked lambda (equivalent to an IIFE in the JavaScript world) that generates a value for us, which we assign to a const value. But what impact does this design decision have on the quality of code generated and the performance? In this episode of C++ Weekly we use the new website quick-bench to test the various options available.

CppCon 2016: Building Software Capital: How to write the highest quality code and why--David Sankel

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

Building Software Capital: How to write the highest quality code and why

by David Sankel

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

This talk discusses the ins and outs of how to write software that is at such a high standard that it gets reused everywhere. It covers organization, design, infrastructure, testing, documentation, reviews, and general suggestions based on my experience in the industry.

There Is A New Future -- Felix Petriconi

Version 1.0 of a new C++ future and channel library has been released.

There Is A New Future

by Sean Parent, Foster Brereton and Felix Petriconi

About the library:

This library provides high level abstractions for implementing algorithms that eases the use of multiple CPU cores while minimizing the contention.

The future implementaton differs in several aspects compared to the C++11/14/17 standard futures: It provides continuations and joins, which were just added in a C++17 TS. But more important this futures propagate values through the graph and not futures. This allows an easy way of creating splits. That means a single future can have multiple continuations into different directions. An other important difference is that the futures support cancellation. So if one is not anymore interested in the result of a future, then one can destroy the future without the need to wait until the future is fullfilled, as it is the case with std::future (and boost::future). An already started future will run until its end, but will not trigger any continuation. So in all these cases, all chained continuations will never be triggered. Additionally the future interface is designed in a way, that one can use build in or custom build executors.

Since one can create with futures only graphs for single use, this library provides as well channels. With these channels one can build graphs, that can be used for multiple invocations.

CppCon 2016: Channels - An alternative to callbacks and futures--John Bandela

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

Channels - An alternative to callbacks and futures

by John Bandela

(watch on YouTube)

Summary of the talk:

Currently in the C++ Networking TS and Concurrency TS, callbacks and futures are the means for communicating an asynchronous value. However, there are disadvantages with both. Callbacks are low overhead, but hard to compose. Futures are easy to compose, but have increased overhead. In this talk we will consider channels as a third alternatives that can have lower overhead than futures while still being easy to compose

CppCon 2016: Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17--Jason Turner

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17

by Jason Turner

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

The Commodore 64 was released in 1982 and is the best selling computer model of all time. At 34 years old, even the most simple embedded processor today outperforms it. Join me on an exploration of how C++17 techniques can be utilized to write expressive, high performance, high level code for simple computers. Together we will create a game for this aging system.

You'll leave the talk with a better understanding of what your compiler is capable of and be able to apply these ideas to create better code on modern systems.

CppCon 2016: Using Types Effectively--Ben Deane

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

Using Types Effectively

by Ben Deane

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

C++ has a pretty good type system, and modern C++ gives us a greater ability than ever before to use that type system for good: to make APIs easier to use and harder to misuse, to make our datatypes more closely express our intent, and generally to make code safer, more obvious in function and perhaps even faster.

This is an interactive session - incorporating games played between presenter and audience, even - taking a look at choices available to us as datatype and API designers, and examining how a little knowledge about the algebra of algebraic datatypes can help. We'll see why std::optional and (hopefully soon) std::variant will quickly become an essential part of everyone's toolbox, and also explore how types can be used to express not just the structure of data, but also the behaviour of objects and functions.