How to convert an enum to string in C++

Enumerations are widely used and we often need to convert enum values to strings (typically for recording values in logs) but there is no option at the language level or a utility in the standard library to make it possible. Therefore, developers are usually handcrafting their own solutions. Let’s say we have the following enum:…

Five examples for avoiding the preprocessor

The C++ preprocessor is a text replacement tool used to transform the source code in order to produce a single text file that is then passed to the actual compiler. It has various capabilities, such as including files, conditional compilation, text macro replacement, error emitting, stringizing, or token concatenation. Often developers use the preprocessor when other alternatives are available and are more appropriate. In this article, I will show five examples of when and how you can avoid the use of the preprocessor.