Why don’t compilers warn for const T f()?

The other day I got an intriguing question from Sándor Dargó. In const all the things?” (2022-01-23) I had written:

Returning “by const value” is always wrong. Full stop.

Sándor writes: “I was wondering — given that it’s really the case, even the Core Guidelines says so, and it seems to be easy to identify — do you know why we don’t have compiler warnings for such return types?”

Read More

Playing A Serf’s Tale (1986)

The other week I was contacted by a fellow digital antiquarian re an erratum in the “Adventure Family Tree” (managed by Nathanael Culver and hosted by Mike Arnautov). That page had listed under “No known download”:

BROO_XXX: “Enhanced” version of WOOD0350, with “added locations, text added, puzzles reworked,” by Nigel Brooks. […] This version was later renamed “A Serf’s Tale, A Retelling of the Original Adventure”.

In fact, wrote our correspondent, A Serf’s Tale is very much alive and well; the ZX Spectrum tape image survives, and is playable in any Spectrum emulator, such as in JSSpeccy on spectrumcomputing.co.uk. Ctrl+F “speccy” on that page, or (modulo link-rot) click here, to play A Serf’s Tale online.

So I spent a few days trying to beat A Serf’s Tale — and eventually succeeded, with the help of several vintage walkthroughs and hint files. Spoilers galore below the break.

Read More

The red right arm of Jove

In Milton’s Paradise Lost, book II (1667), Belial counsels against an assault on Heaven:

What if the breath that kindl’d those grim fires
Awak’d should blow them into sevenfold rage
And plunge us in the flames? or from above
Should intermitted vengeance arm again
His red right hand to plague us?

This last image is lifted from Horace’s Odes I.2:

Iam satis terris nivis atque dirae
grandinis misit Pater et rubente
dextera sacras iaculatus arces
terruit urbem […]

Read More

noexcept affects libstdc++’s unordered_set

The other day I learned a new place where adding or removing noexcept can change the performance of your program: GNU libstdc++’s hash-based associative containers change the struct layout of their nodes depending on the noexceptness of your hash function. This is laid out fairly clearly in the docs; it’s simply bizarre enough that I’d never thought to look for such a thing in the docs!

Read More

Make things simpler than possible

A quotation from the preface to Donald Knuth’s The TeXBook (Amazon, archive.org):

[A] noteworthy characteristic of this manual is that it doesn’t always tell the truth. When certain concepts of TeX are introduced informally, general rules will be stated; afterwards you will find that the rules aren’t strictly true. […] The author feels that this technique of deliberate lying will actually make it easier for you to learn the ideas. Once you understand a simple but false rule, it will not be hard to supplement that rule with its exceptions.

Read More

A priority_tag-like pattern for type-based metaprogramming

Via Enrico Mauro, an interesting variation on the priority_tag trick. Compare the following example to the HasSomeKindOfSwap example in priority_tag for ad-hoc tag dispatch” (2021-07-09).

template<class T, int N = 2, class = void>
struct HasSomeKindOfValueType
  : HasSomeKindOfValueType<T, N-1> {};

template<class T>
struct HasSomeKindOfValueType<T, 2, std::void_t<typename T::value_type>>
  : std::true_type {};
Read More

How the STL uses explicit

One of the papers on the docket for this week’s WG21 meeting in St Louis is P3116 “Policy for explicit (Zach Laine, 2024). The idea of “policy,” in this context, is that LEWG wants to have something like a “style guide” for proposal-authors. If a proposal comes in with noexcept in the wrong places, or explicit, or [[nodiscard]], we want to be able to quickly tell the author how it ought to be, without a lot of the same discussion happening on every paper. Like a house style guide in newspaper-editing: if our newspaper uses the Oxford comma, and you bring in an article without it, then we can just point to the style guide, make the fix, and move on [see?], without a lot of repeated discussion of the pros and cons of the comma except insofar as you can argue that it belongs in this particular article for a really good reason.

Read More

Who uses P2786 and P1144 for trivial relocation?

On Friday, June 28th, there will be a discussion at the C++ Committee meeting about the state of “trivial relocation” in C++. (The meeting is physically in St Louis, but also streamed remotely via Zoom and open to visiting experts per WG21’s Meetings and Participation Policy.) If you’re an expert (read: a library maintainer or developer) with opinions or experience on “trivial relocation” — especially if you have implemented it in your own codebase — I encourage you to read the participation policy and try (virtually) to show up for the discussion!

Read More

Tangent circles of integer radius

Over on Puzzling StackExchange, Brandan Williams poses the following interesting question:

Find a strictly decreasing sequence of integers \(r_0, r_1, r_2,\ldots, r_n\) such that you can place kissing circles of radii \(r_1, r_2,\ldots, r_n\) around a central circle of radius \(r_0\). That is, circle \(r_0\) will be tangent to all \(n\) other circles, and circle \(r_i\) will be tangent to circle \(r_{i+1}\) for all \(1\leq i<n\), and circle \(r_n\) will be tangent to circle \(r_1\).

Read More