logoalt Hacker News

tniemi • today at 1:45 PM • 2 replies • view on HN

That `(1 ? (item) : (list)->payload)` was a neat trick. It gets optimized away, but the type comparison happens before that.

Still feels a bit like a party trick, but if it works...


Replies

JdeBP • today at 2:59 PM

It's somewhat of a forced trick nowadays, I think.

I actually thought from the title before I read the article that it was going to use _Generic, as in something like _Generic((item),__typeof__((list)->payload):...) .

Xirdus • today at 2:02 PM

Expressions that compile but never evaluate are bread and butter in C++ template metaprogramming.