krzaq.cc - /dev/krzaq

Example domain paragraphs

A few nights ago a friend asked me if I had any idea how to make his magic macro work. The general idea behind it was simple: for strings known at the compile time, return type parametrized on the string hash; otherwise return a runtime type. He even provided the type trait he uses to determine if we’re dealing with a string literal. It works well for his case and its potential wrongness is not the point of this article.

The point was something else: let us define a macro NAME and classes Const<size_t> and Runtime , such that the following is valid code:

Always willing to help, I sat down to show him how the C++20 solution would like, then how to do a simple tag-dispatch, and to see if the macro could be replaced with a function call.

Links to krzaq.cc (5)