# Fun with conversion-operator name lookup

As of this writing (but perhaps not for very much longer!) the four mainstream compilers on Godbolt Compiler Explorer give four different answers for this simple C++ program:

# It’s not always obvious when tail-call optimization is allowed

I initially wrote this as part of a new entry in “A C++ acronym glossary” (2019-08-02), but decided that it would be better to pull it out into its own post.

# The Box of Delights

I’ve just finished reading John Masefield’s The Box of Delights (1935). I had picked it up at random in a tourist-trap gift shop several months ago, knowing only that it appeared vaguely Christmassy — not knowing at the time that it is (apparently) a giant of British Christmas pop culture, on par with The Nutcracker.

# A better 404 polyglot

Between 2009-ish and 2018, StackOverflow’s 404 page displayed the following polyglot program:

# define v putchar
#   define print(x) ⏎
main(){v(4+v(v(52)-4));return 0;}/*
#>+++++++4+[>++++++<-]>⏎
++++.----.++++.*/
print(202*2);exit();
#define/*>.@*/exit()


This program was originally due to Mark Rushakoff, who later proposed a shorter version: …

# How do C++ using-directives work?

Recall that in C++ there’s a difference between a using-declaration and a using-directive.

# The STL is more than std::accumulate

Conor Hoekstra gives great talks on algorithms. Notably, “Algorithm Intuition” (C++Now 2019) and “Better Algorithm Intuition” (code::dive 2019). However, every time I watch one of his talks where he uses STL algorithms to solve some programming problem, I come away feeling like

Let’s look at two examples of “using STL algorithms to solve problems” in this limited sense, and how else we might solve them. Both of these examples are taken from Conor’s CppCon 2020 talk “Structure and Interpretation of Computer Programs: SICP.”

# Bubblesort, rocksort, and cocktail-shaker sort

I’m currently participating in a book club for Donald Knuth’s The Art of Computer Programming. It’s run by Zartaj Majeed; you can find the details on Meetup here.

# Tips re operator()

Several times this week I’ve seen people talking about C++20’s new generic lambdas with explicit template parameters. Time for a blog post so I can link to it…

# “Flash of unstyled base class”

This week I ran into an interesting bug in the unit tests for some multithreaded code. The setup for the test involved a “process status daemon” that (in production) polled some global state once per second, and also provided some auxiliary functions that we wanted to test. The “once per second” code came from an old and widely-used internal helper library. In this retelling, I’ve taken the liberty of updating it for C++20:

# An example of the Barton–Nackman trick

I still need to write the blog post explaining “What is the Hidden Friend Idiom?”; but for now, here’s a practical demonstration of its usefulness that just came up on the cpplang Slack (thanks, Johan Lundberg!).

# How to use a private member from outside the class

Am I missing some subtle mechanism by which “unused” private members might actually be referenced from other TUs?

Indeed, I was! Check this out (Godbolt): …

# How different compilers deal with provably unused entities

The other day, I was asked whether we should worry about the space taken up by unused functions in our codebase. My answer followed this rambling path:

# Type-erased UniquePrintable and PrintableRef

Here’s a simple type-erased UniquePrintable (owning, value-semantic, move-only), and a simple type-erased PrintableRef (non-owning, reference-semantic, trivially copyable). Notice that they use two different techniques internally, and that both techniques are simple enough to memorize and bang out in five minutes the next time you need type erasure.