Articles & Books

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.

 

Quick Q: How does virtual inheritance solve the “diamond” (multiple inheritance) ambiguity?

Quick A: by making sure only one instance of each parent class is created.

Recently on SO:

How does virtual inheritance solve the “diamond” (multiple inheritance) ambiguity?

You want: (Achievable with virtual inheritance)

  A 
/ \ 
B   C 
\ / 
  D

And not: (What happens without virtual inheritance)

A   A 
|   |
B   C 
\ / 
  D

Virtual inheritance means that there will be only 1 instance of the base A class not 2.

Your type D would have 2 vtable pointers (you can see them in the first diagram), one for B and one for C who virtually inherit A. D's object size is increased because it stores 2 pointers now; however there is only one A now.

So B::A and C::A are the same and so there can be no ambiguous calls from D. If you don't use virtual inheritance you have the second diagram above. And any call to a member of A then becomes ambiguous and you need to specify which path you want to take.

New new() - The C++17's Alignment Parameter for the operator new() -- Bartlomiej Filipek

C++17's new and handy new operator that supports overaligned objects!

New new() - The C++17's Alignment Parameter for Operator new()

by Bartlomiej Filipek

From the article:

The whole deal about the new functionality is that you can forgot about the limitation of over-aligned data. It lets you write regular modern C++ code without worrying about specialized allocators or raw memory handling functions like std::aligned_alloc() or _aligned_malloc().