Articles & Books

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...

Modern C++ Programming Cookbook Review

Review of a new book about Modern C++

Modern C++ Programming Cookbook Review

by Bartlomiej Filipek

From the article:

The book is good addition to any C++ bookshelf. It’s well suited for the target audience: even if you’re an expert, you’ll get a chance to refresh your knowledge and update it with C++14/C++17 content. And If you’ve just finished some beginner book, you’ll find here topics that will move you forward.

The rise of the new language MC++--CppDepend Team

A new language?

The rise of the new language MC++

by CppDepend Team

From the article:

During  the last few years we talk about the “C++ Renaissance”. We have to admit that Microsoft was a major actor of this movement, I remember this video where Craig Symonds and Mohsen Agsen talked about it.

In 2011 Microsoft announced in many articles the come back of C++, and Microsoft C++ experts like Herb Sutter did many conferences to explain why C++ is back and mostly recommend the use of Modern C++. In the same time the standard C++11 was approved and we begin to talk about  C++ as new  language...

C++17 in details: Templates--Bartlomiej Filipek

What's new in C++17?

C++17 in details: Templates

by Bartlomiej Filipek

From the article:

Do you work a lot with templates and meta-programming?
With C++17 we get a few nice improvements: some are quite small, but also there are notable features as well! All in all, the additions should significantly improve writing template code.

Today I wrote about:

  • Template argument deduction for class templates
  • template<auto>
  • Fold expressions
  • constexpr if
  • Plus some smaller, detailed improvements/fixes

BTW: if you’re really brave you can still use concepts! They are merged into GCC so you can play with them even before they are finally published.

Making things do stuff – Part 6--Glennan Carnie

The series continues.

Making things do stuff – Part 6

by Glennan Carnie

From the article:

As code designers we tend to eschew specific ‘stove-pipe’ code in favour of reusable code elements.  Up until now we’ve been coding some very specific examples so it’s probably worth looking at some more generic solutions.

In this article we’ll look at building generic register manipulation classes (or, as one commenter referred to them, ‘register proxy’ classes).  Here, we’re really exploring code design rather than coding ‘mechanics’.  I’m using this to explore some factors like the balance between efficiency, performance and flexibility...

Making things do stuff – Part 5--Glennan Carnie

The series continues.

Making things do stuff – Part 5

by Glennan Carnie

From the article:

We’ve been looking at using C++ to manipulate I/O hardware.   Previously, we’ve looked at the fundamentals of hardware manipulation; and how to encapsulate these mechanisms into classes.  If you’ve not been following along I’d recommend reading the previous articles first before continuing.

This time we’ll explore a lesser-known feature of C++ and its application in hardware manipulation – placement new...

Making things do stuff – Part 4--Glennan Carnie

The series continues.

Making things do stuff – Part 4

by Glennan Carnie

From the article:

In the last article we explored the design of a class to encapsulate a physical hardware device.  In that article I deliberately ignored how the class would actually interact with the hardware.

In this article we explore the options available to us for accessing hardware and the consequences of those choices...

A unique_ptr pool --Jens Weller

Discussion regarding self contained unique_ptr pool implementation.

A unique_ptr pool

by Jens Weller

From the article:

A few weeks ago I wrote about a self-contained unique_ptr pool, which today I refactored into a more reuseable template. Reason is, that the pool class it self now needs to maintain two different kind of objects into their pools,  hence the actual pool code is best now factored out into a template.