How my papers did at Hagenberg
“Not great, Bob!”
Arthur O’Dwyer
Stuff mostly about C++
How my papers did at Hagenberg
“Not great, Bob!”
Like
I’ve recently engaged in book-club discussions on the following classic papers in the field of “artificial intelligence”:
Dante’s hypersphere in THREE.js
Mark A. Peterson’s essay “Dante and the 3-sphere” (Am. J. Phys. 47(12), December 1979) suggests that when, in Paradiso 27, Dante looks from the starry sphere upward in the direction of the Empyrean and downward in the direction of Earth, and when he sees that nine concentric circles of angels above mirror the nine concentric planetary spheres below, he is “groping for a language to express an idea conceived intuitively and nonverbally” — namely, the idea of “how a 3-sphere would look from its equator.”
The crossword from Bored to Death S2E5
In HBO’s Bored to Death episode S2E5 “Forty-Two Down,” protagonist Jonathan Ames (Jason Schwartzman) introduces himself to his target Vikram (Ajay Naidu) by asking his help with that day’s New York Times crossword. We get two brief shots of the crossword itself. The first, a closeup, is just enough to irk the crossworders in the audience, as we see a plethora of unkeyed letters. The second medium shot shows that the black squares in this asymmetric grid spell out the word “HIT.” (Or does the black blob in front of the “H” represent a fourth letter?)
The episode aired 2010-10-24, but the Times shown is mostly the issue of Wednesday 2007-11-14: the facing column contains Mike Hale’s review of the TV show Kenny vs. Spenny, and the “Answer to Previous Puzzle” at lower left is indeed Fred Piscop’s puzzle of 2007-11-13. The crossword, however, is completely doctored — I see no resemblance to the Jim Page puzzle that actually ran on that date. The clues (which do not match the grid) are hilariously zany!
“Trivially relocatable” versus “trivially destructible after move”
Recently I discovered that besides the various libraries using P1144-style (or occasionally P2786-style) trivial relocatability, there are also at least two that use P1029R2-style “trivial destructibility after move.”
This blog post demonstrates the difference between is_trivially_relocatable
and is_trivially_destructible_after_move
.
Semantically ordered arguments, round 2
Back in 2021, I wrote that “Semantically ordered arguments should be lexically ordered too.” Two minor updates in that area, which are large enough to deserve a post of their own.
Fully Schrödinger crosswords
In December, Kory Mathewson tweeted this puzzle-creation challenge:
Create a 5x5 crossword puzzle with two distinct solutions. Each clue must work for both solutions. Do not use the same word in both solutions. No black squares.
Here’s my offering; solutions given at the end of this post.
Does v.clear()
free the allocation?
A perennial question on the cpplang Slack:
“When I call v.clear()
on a vector, does that hang onto the heap allocation,
or free it?” The short answer is: “It hangs onto the allocation. Follow up with
v.shrink_to_fit()
if you need the allocation eagerly returned.”
Now here’s the long answer!
What I watched and read this year
In 2024, for the first time, I kept a record of the media that I took in this year. Well, not “media” in the news-media sense (however relevant that might have been), but in the sense of books, films, stage shows; and to a lesser extent, journal articles, magazines, TV series, and long-form online content.
“Cumbersome” labeled loops and the C preprocessor
In my last post I wrote that N3377’s proposed syntax for labeled loops in C was not only unprecedented among programming languages but also “cumbersome.” What did I mean by that?
Labeled loop syntax in many languages
Many existing languages support labeled loops, such that you can say break foo;
to break
out of the loop labeled foo
, instead of just breaking from the smallest enclosing loop.
The C programming language just gained labeled loops, too, with the adoption of
N3355 “Named loops” (Alex Celeste, 2024).
Erich Keane and Aaron Ballman reacted to N3355’s adoption with N3377 “An Improved Syntax for N3355,” which I very much hope will be voted down. It’s an “interesting” proposal, in that the authors are compiler engineers who work on a polyglot compiler (Clang), and yet they don’t seem to consider consistency with other languages to be a positive for C at all.
Field-testing -Wassign-to-class-rvalue
Perennially it is noticed that C++ forbids assignment to scalar rvalues, while permitting assignment to class rvalues. That is:
T f();
f() = "xyz";
is forbidden when T=const char*
, but permitted when T=string
.
When ranges::for_each
behaves differently from for
This week I learned an interesting and dismaying fact:
C++11’s range-based for
loop and C++20’s ranges::begin
/end
use different protocols to find the “beginning” and “end” of a range!
Should std::expected
be [[nodiscard]]
?
A correspondent writes to me that he’s switched from throw/catch
exceptions to C++23’s std::expected
in all new code. That is, where a traditional C++ program would have:
int f_or_throw();
int g_or_throw() {
f_or_throw();
// arguably OK, discards f's result
// but propagates any exceptional error
return 1;
}
his programs always have:
using Eint = std::expected<int, std::error_code>;
[[nodiscard]] Eint f_or_error() noexcept;
Eint g_or_error() {
return f_or_error().transform([](int) {
return 1;
});
}
In the former case, we “discard” the result of f_or_throw()
by simply discarding
the value of the whole call-expression. That’s safe, because errors are always
signaled by exceptions, which will be propagated up the stack regardless of what
we do with the (non-exceptional, non-error) return value. This ensures that the
error is never swallowed except on purpose.
The Elements of Programming Style (1974)
In October’s Overload magazine Chris Oldwood muses on Italo Calvino’s definition of what makes a book a “classic” (“Why Read the Classics?”, 1986). Calvino’s essay suggests fourteen different ways of describing the elephant that is “a classic,” including:
Shifting objects by less than sizeof(T)
This morning I watched the video of Christopher Fretz’s talk from C++Now 2024, “Designing a Slimmer Vector of C++ Variants.” I recommend it! I found two interesting things to say about it:
Wolf (1906) on the false Quijotes of Avellaneda and Lesage
Earlier this year I joined a book club reading Don Quijote and got deep enough into it to seek out the “false second volume of Quijote” of Alonso Fernández de Avellaneda, the book that Don Quixote catches Don Jerónimo and Don Juan reading in Chapter 59 of Cervantes’ actual Part II.
“Why do you want us to read all that nonsense, Don Juan? Nobody who has read the first part of the history of Don Quixote de la Mancha can possibly derive any pleasure from reading this second part.”
“All the same,” said Don Juan, “it’ll be as well to read it, because there’s no book so bad that there isn’t something good in it.”
Martin Gardner Scientific American Index; Rule 110 challenge
Today is the 110th birthday of Martin Gardner (1914–2010)! Every year around this date, various groups hold “Celebration of Mind” festivals. You can find some examples on the Gathering 4 Gardner site, although I see at the moment it’s a little sparse and 404’ish.
What I’m reading lately: Greppability, Hebb’s dictum
A few good blog posts and things (by other people) that I’ve seen lately:
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?”