Articles & Books

Alternatives to C++ Function Pointers in SYCL using Function Objects -- Georgi Mirazchiyski

This blog post offers an interesting solution for replacing function pointers with function objects and lambdas.

Alternatives to C++ Function Pointers in SYCL using Function Objects

by Georgi Mirazchiyski

From the article:

Function Pointers are a feature of the C language and so form part of the C++ standard. As such, a function pointer allows the following behavior:

    "A pointer to a function can be passed as a parameter to another function"

In C++, especially in modern C++, function pointers are a legacy feature from the C language but they still exist in some code bases.

SYCL enables single source development where template functions can contain both host and device code to construct complex algorithms that use acceleration. However, SYCL does not provide support for function pointers since this is a limitation posed by the design of OpenCL v1.2 which is the basis of the current SYCL v1.2.1 definition.

But there is good news, we can use modern C++ to implement a solution that can be used with SYCL. SYCL is built with C++11 (and onward depending on the implementation), meaning features like anonymous functions known as "lambdas" can be used with little to zero overhead. Even going back to C++98/03 it is possible to use function objects defined as either structs or classes, and additionally, you can template your operation (the computation logic) to provide a generic way to consume the function objects or lambdas.

 

C++ Tricks: Fast RTTI and Dynamic Cast--Samuel Kahn

Only for special cases.

C++ Tricks: Fast RTTI and Dynamic Cast

by Samuel Kahn

From the article:

As introduced in the first post of these series, I will share the first piece of KCL: an implementation of RTTI and Dynamic Cast. The code can be found on GitHub.

If you don’t know what dynamic casting is, then I suggest you read some online resources before diving into this article...

Expressive Code for State Machines in C++--Valentin Tolmer

Compiler checks are the best!

Expressive Code for State Machines in C++

by Valentin Tolmer

From the article:

Have you ever run into this kind of comments?

// IMPORTANT: Do not call this function before calling SetUp()!

Or checks like these:

if (my_field_.empty()) abort();

Those are all symptoms of a (often light-weight) protocol that our code must respect. Or sometimes, you have an explicit protocol that you’re following, such as in the implementation of an SSL handshake or other business logic. Or maybe you have an explicit state machine in your code, with the transitions checked each time against a list of possible transitions.

Let’s have a look at how we can expressively handle these cases...

fixing c++ with epochs -- Vittorio Romeo

This article covers a possible mechanism that would allow the C++ committee to make breaking changes to the language syntax while still fully preserving backwards compatibility. This would allow dangerous or obsolete constructs to be removed from C++, increasing safety and approachability of the language.

fixing c++ with epochs

by Vittorio Romeo

From the article:

Imagine that you have been designing a programming language for over 30 years and that it gradually became widely used across the globe. Some of the decisions you made at the beginning were excellent and contributed to the success of your project. Some others, however, were not the best: over the years you and your users realized that the world would have been a better place if those choices you made eons ago were slightly different. [...]

What if I told you that I could fix all of your problems? Even better, what if I told you that backward-compatibility will never be broken and that migration to newer versions of your language could be automated?

C++17 In Detail - Available in Print!

Another book available in Print that describes C++17 features!

See the article that shows more about this release:

C++17 In Detail - Print Version!

by Bartlomiej Filipek

About the book:

C++17 is a major update to the language and brings many exciting additions and improvements that will change your pre for the better. This book shows you all of the significant changes in the new Standard.

I spent hundreds of hours investigating how the new features work to ensure this book is helpful and practical. It will not only save you time but will guide you through lots of nuances of the language and the Standard Library.

If you have experience with C++11/14 and you want to advance to the latest C++ Standard, then pick up the book and start reading.