« Google Signals WFH is Acceptable From Now On (Updated) | Main | LEDAS Reports on Business Through COVID-19 »

May 25, 2020



Hello Andrey,

Thank you for an amazing article, this hack is a very interesting one! Unfortunately, the code of the compile-time counter looks like it is cannot be compiled with clang 13. I mean the static asserts fail and the counter is not being increased after each static_assert, the function `next()` always returns zero.

I've fixed the code with the following changes, I hope it could be suitable for the readers.

1. Use just typename = decltype([]{}) as the last template parameter in the reader(int) template function instead of auto = unique(). I have no idea why, but the compiler cached values without this change and reader<0>(int{}) just returned 0 in the first time (since the overloading for float was selected) and 1 all the times after this.

2. Add another int template parameter in the next() function template before the R, R should depend on this new parameter:

template (int{})>
constexpr int next() {
return R;

Without this change, the next() function just returned 0 even if the reader<0>(int) works as expected (so, as the counter).

Anyway the post is very useful for every C++ learner and professional.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name is required. Email address will not be displayed with the comment.)


Search This Blog



Thank you for visiting!