It is always a pleasure to watch a talk from Andrei Alexandrescu. Here is the detail of one slide about declarative control flow.

I am glad I have this slide, because no matter what I talk about, I could talk about like rocket surgery, ok, anything, and at the end of the talk, there is this guy who comes and says "you know that macro thing, how did you do it?"
#define CONCATENATE_IMPL(s1,s2) s1##s2
#define CONCATENATE(s1,s2) CONCATENATE_IMPL(s1,s2)

#ifdef __COUNTER__
#define ANONYMOUS_VARIABLE(str) \
  CONCATENATE(str, __COUNTER__)
#else
#define ANONYMOUS_VARIABLE(str) \
  CONCATENATE(str, __LINE__)
#endif
int main() {
  int ANONYMOUS_VARIABLE(foo);
  int ANONYMOUS_VARIABLE(foo);
}

clang++ with -E option outputs:

int main() {
  int foo0;
  int foo1;
}

Bonus question

Why an indirection is used?

#define CONCATENATE(s1,s2) CONCATENATE_IMPL(s1,s2)

It expands the values:

int CONCATENATE_IMPL(foo, __LINE__);
int CONCATENATE(foo, __LINE__);

clang++ with -E option outputs:

int foo__LINE__;
int foo17;

Note

If you have any questions or suggestions that you would share with me, write me an email. For typographical errors or dead links, send me a pull request.