Macro trick

Sometimes you need to create some enum, and for each of the values you want to assign some additional information – a string. Imagine a lookup function that based on some constant returns a description of the provided value. Nothing special – first thing that comes to your mind might be a global instance of std::map, right? enum Color { Red, Green, Blue }; std::map<Color, std::string> kColors{ {Red, "#ff0000"}, {Green, "#00ff00"}, {Blue, "#0000ff"}}; std::string HTML(const Color color) { return kColors[color]; } We have constants for colors, we store HTML values for each of the color constant and when there is a need to check its html value we just do a lookup.

Hello, world!

#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; } I will post something interesting here every often. Stay tuned!