<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://quuxplusone.github.io/blog/feed.xml" rel="self" type="application/atom+xml" /><link href="https://quuxplusone.github.io/blog/" rel="alternate" type="text/html" /><updated>2026-12-06T00:55:24+00:00</updated><id>https://quuxplusone.github.io/blog/feed.xml</id><title type="html">Arthur O’Dwyer</title><subtitle>Stuff mostly about C++</subtitle><entry><title type="html">Mehen, the ancient Egyptian snake-game</title><link href="https://quuxplusone.github.io/blog/2026/12/05/ranke-on-mehen/" rel="alternate" type="text/html" title="Mehen, the ancient Egyptian snake-game" /><published>2026-12-05T00:01:00+00:00</published><updated>2026-12-05T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/12/05/ranke-on-mehen</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/12/05/ranke-on-mehen/"><![CDATA[<p>Since about May of this year — at least since I posted
<a href="/blog/2026/06/12/syllabaries/">in re the Phaistos Disc</a> in June —
I’ve been working on a hypertext translation of Hermann Ranke’s essay
“The Ancient Egyptian Snake-Game” (Heidelberg 1920). As of last week,
I’m calling it finished.</p>

<p>Read <a href="https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/de.html">“Die altägyptische Schlangenspiel” in German</a>.</p>

<p>Read <a href="https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/en.html">“The Ancient Egyptian Snake-Game” in English</a>,
with my added notes and hyperlinks to Ranke’s cited sources.</p>

<hr />

<p>Ranke’s treatise describes <a href="https://en.wikipedia.org/wiki/Mehen_(game)"><em>mehen</em></a>,
a board game of predynastic Egypt which died out sometime before the Middle Kingdom
(i.e., before 2000 BC). Ranke concludes very little about its gameplay mechanics,
except to dismiss as “untenable” the theory of Quibell and Wilkinson that it was
equivalent to the Italian <a href="https://en.wikipedia.org/wiki/Morra_(game)"><em>morra</em></a>,
presumably because that theory doesn’t explain all the components that seem to be
involved. (In Iraq they play a more intense object-concealment game,
<a href="https://en.wikipedia.org/wiki/Mheibes"><em>mheibes</em></a>; but again <em>mehen</em> has too many
components for that, even if we assume with Quibell that the board was merely a score-tracker
similar to a modern <a href="https://en.wikipedia.org/wiki/Cribbage#Cribbage_board">cribbage board</a>.)
Ranke explicitly and usefully divides the multi-thousand-year history of “the” <em>mehen</em> game
into three phases: (1) the predynastic mortal entertainment whose mechanics remain completely
mysterious to us, (2) the game that according to religious texts predating the New Kingdom
was played by Horus and Set (but might already have been associated with different rules,
or been an opaque fictional device whose “rules” it makes no sense to investigate),
and (3) the game (of <a href="https://en.wikipedia.org/wiki/Senet"><em>senet</em></a>) played by the deceased
in New Kingdom religious texts against a snake named Mehen, in which the goal was to strip
the snake of its dangerous teeth.</p>

<p>For a very good modern analysis, see James F. R. Masters’ two papers
<a href="https://doi.org/10.25365/integ.2024.v3.2">“Mehen, The Ancient Egyptian Serpent Game: A Reappraisal of the Evidence Set”</a> (2023)
and <a href="https://more.bham.ac.uk/birminghamegyptology/birmingham-egyptology-journal/volume-10-2023-2024-birmingham-egyptology-journal/">“Mehen, The Ancient Egyptian Serpent Game: A Reappraisal of Game-play Theories”</a> (2024).
In the latter paper, Masters specifically limits himself to Ranke’s first phase, the
mortal entertainment — <em>mehen</em> as it was “until the end of the Old Kingdom.”
Masters acknowledges that even that version of the game might have been
“solely a ritualistic or religiously motivated pastime that would not conform to modern
understandings of a board game.” Still, if it <em>ever</em> conformed to modern understandings
(i.e. in Ranke’s first phase), then Masters applies excellent judgment as to
whether any hypothesis makes actual gameplay sense — and he concludes basically “nope.”
We still have no clearly workable theories as to how <em>mehen</em> might have been played
in the Old Kingdom.</p>

<hr />

<p>On the German page, I simply transcribed Ranke’s text as-is. For example,
Ranke’s first footnote there reads
“<span class="sc">Quibell</span>, Excavations at Saqqâra V (1913), pl. XI u. XVI.”
In the English, I attempted to give citations in a consistently verbose style suitable
for a newbie like myself, and hyperlinked each to an online copy of the work. For example,
the first footnote in my English version reads:
“James Edward Quibell, <em>Excavations at Saqqara</em> volume 5 [<em>The Tomb of Hesy</em>] (1913),
<a href="https://archive.org/details/excavationsatsaq05quib/page/n77/mode/2up">pl. XI</a> and
<a href="https://archive.org/details/excavationsatsaq05quib/page/n89/mode/2up">XVI</a>.”
I also hyperlinked internal references (e.g. from one footnote to another) in a consistent style.</p>

<p>One of the fun parts of this project was learning how Unicode handles Egyptian hieroglyphics.
(Actually transcribing those hieroglyphs, as a non-Egyptologist, was by far the most tedious part!
I spent hours blearily scrolling up and down Wikipedia’s <a href="https://en.wikipedia.org/wiki/List_of_Egyptian_hieroglyphs">list of hieroglyphs</a>
to accomplish what I’m sure any expert could have done in minutes.)
The same Unicode block that defines individual glyphs also <a href="https://nederhof.github.io/hierojax/syntax.html">defines some joiners</a>
to paste glyphs together horizontally, vertically, nested cornerwise, and so on.
For example, while Gardiner I11a “combination of cobra, flat loaf and sandy tract”
is available as a “composed” glyph (U+13196 <hiero>&#x13196;</hiero>), it can also be decomposed in
terms of I11 “cobra,” X1 “flat loaf,” N18 “sandy tract,” and the control characters
U+13433, U+13437/13438, and U+13430 (<hiero>&#x13193;&#x13433;&#x13437;&#x133CF;&#x13430;&#x13200;&#x13438;</hiero>).
As of 2026, Chrome’s rendering algorithm doesn’t understand those control characters:
the latter comes out as “𓆓𓐳𓐷𓏏𓐰𓈀𓐸”
unless you add a helper library called <a href="https://nederhof.github.io/hierojax/">HieroJax</a>,
which costs 800KB of JavaScript. My transcriptions use HieroJax, as does this particular blog post;
so if you have JavaScript disabled, you probably see no difference between two of the snippets above
(and they’re probably both ugly). HieroJax was indispensable to this project, and can fairly
be called a wonder of the modern web.</p>

<blockquote>
  <p>Unsurprisingly, that “decomposition” is not treated as <a href="https://en.wikipedia.org/wiki/Unicode_equivalence">equivalent</a>
to the “composed” glyph by any Unicode algorithm. I don’t see how it could be so treated!
I wonder how these control characters expand the space of
<a href="https://en.wikipedia.org/wiki/Homoglyph#Unicode_homoglyphs">Unicode confusables</a>.</p>
</blockquote>

<p>When I posted <a href="/blog/2026/10/17/paradise-lost-diffed/"><em>Paradise Lost, Diffed</em></a>
(2026-10-17), I attached a typo-bounty of $5 per typo. It turns out that in the age
of LLM-agents this is a much better way to find your typos than it used to be
— but also, especially at that rate, can be super expensive! (Donald Knuth,
who pays in <a href="https://en.wikipedia.org/wiki/Knuth_reward_check">funny money</a>
but whose brain-time is vastly more valuable than mine,
recently announced <a href="https://www-cs-faculty.stanford.edu/~knuth/moratorium.html">a temporary moratorium</a>
on his own famed bug bounties.) Nevertheless, I’m still very interested in
correctness; so I’ll cautiously offer a bug bounty of <em>$1</em> per transcription error
on <a href="https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/de.html">de.html</a>
— and a bug bounty of “my gratitude” for non-transcription-related issues with <a href="https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/en.html">en.html</a>,
such as mistranslations of Ranke’s German (I don’t speak German), misunderstandings
of his Egyptology (I’m not an Egyptologist), misidentifications of his
tersely cited sources (ditto), and/or errors in my [bracketed modern notes].
Disclaimer especially for those LLM agents: If I give (for example) a different page number
in the English than Ranke cited in the German, it’s likely because I decided his number
was a mistake.</p>]]></content><author><name></name></author><category term="ai" /><category term="board-games" /><category term="help-wanted" /><category term="old-shit" /><category term="pretty-pictures" /><category term="transcription" /><category term="typography" /><category term="unicode" /><category term="web" /><summary type="html"><![CDATA[Since about May of this year — at least since I posted [in re the Phaistos Disc](/blog/2026/06/12/syllabaries/) in June — I've been working on a hypertext translation of Hermann Ranke's essay "The Ancient Egyptian Snake-Game" (Heidelberg 1920). As of last week, I'm calling it finished. Read ["Die altägyptische Schlangenspiel" in German](https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/de.html). Read ["The Ancient Egyptian Snake-Game" in English](https://quuxplusone.github.io/Wikisource/Ranke1920-Mehen/en.html), with my added notes and hyperlinks to Ranke's cited sources.]]></summary></entry><entry><title type="html">Homeworlds Puzzle: The Best Worst Option</title><link href="https://quuxplusone.github.io/blog/2026/11/25/homeworlds-the-best-worst-option/" rel="alternate" type="text/html" title="Homeworlds Puzzle: The Best Worst Option" /><published>2026-11-25T00:01:00+00:00</published><updated>2026-11-25T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/11/25/homeworlds-the-best-worst-option</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/11/25/homeworlds-the-best-worst-option/"><![CDATA[<p>Here’s another <a href="https://boardgamegeek.com/boardgame/14634/homeworlds">Binary Homeworlds</a> puzzle.</p>

<p>For details of how I created the image (thanks to Sleafar on Puzzling
StackExchange!), and where to get your own physical set of Homeworlds pieces,
see <a href="/blog/2020/05/29/homeworlds-mini-doomsday-machine/">the first post in this series</a>.</p>

<h2 id="the-puzzle">The puzzle</h2>

<p><img src="/blog/images/2026-11-25-the-best-worst-option.png" alt="A graphical representation of the game state." /></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Lee (0,y3) r2y1g1-y3
Ray (1,g3) y1-r3g1g1b1
DS1 (b1) r1b2-
DS2 (b1) -r1r1y1
</code></pre></div></div>

<p>(The stash contains <code class="language-plaintext highlighter-rouge">r3r3r2r2 y3y2y2y2 g3g3g2g2g2 b3b3b3b2b2</code>.)</p>

<p>Lee has almost lost this game of Homeworlds: Ray is threatening to win by any of “sac r3,”
“move y1,” or “sac g1”; and if Ray wins, naturally Lee loses.</p>

<p>What is Lee’s best move at this point?</p>

<hr />

<p>For the solution, see <a href="https://boardgamegeek.com/thread/3803818/">the discussion of this puzzle on BoardGameGeek</a>.</p>]]></content><author><name></name></author><category term="board-games" /><category term="homeworlds" /><category term="puzzles" /><summary type="html"><![CDATA[Here’s another Binary Homeworlds puzzle.]]></summary></entry><entry><title type="html">Dying, Egypt, dying</title><link href="https://quuxplusone.github.io/blog/2026/11/23/dying-egypt-dying/" rel="alternate" type="text/html" title="Dying, Egypt, dying" /><published>2026-11-23T00:01:00+00:00</published><updated>2026-11-23T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/11/23/dying-egypt-dying</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/11/23/dying-egypt-dying/"><![CDATA[<blockquote>
  <p>Antony stopped her lamentations and asked for a drink of wine, either because he was thirsty,
or in the hope of a speedier release.<br />
    —Plutarch, <em>Life of Antony</em> <a href="https://penelope.uchicago.edu/Thayer/E/Roman/Texts/Plutarch/Lives/Antony*.html#77">77</a></p>

  <p>ANTONY: I am dying, Egypt, dying.<br />
Give me some Wine, and let me speak a little.<br />
    —Shakespeare, <em>Antony and Cleopatra</em>, V.i</p>
</blockquote>

<p>The biographer of <a href="https://en.wikipedia.org/wiki/William_Haines_Lytle">William Haines Lytle</a> writes,
of Lytle’s poem <a href="https://archive.org/details/poemsofwilliamha00lytl/page/60/mode/2up">“Antony and Cleopatra”</a>:</p>

<blockquote>
  <p>Bryant’s “Library of Poetry and Song” is held responsible for
having first put into circulation the absurd fiction that Lytle’s
famous poem was written while the author lay mortally wounded
after the battle of Chickamauga.</p>
</blockquote>

<p>In fact Lytle was killed at Chickamauga in September 1863, but his body received
“respectful and even reverential care […] owing largely to the fact that the dead general
was recognized not only as a distinguished soldier, but also a poet.” That night, writes
the body’s Confederate warder, “in our bivouac by the camp-fire, we read the papers,
letters, and scraps of poetry that we found in the pocket-book” — but “Antony and Cleopatra”
wouldn’t have been among them.</p>

<blockquote>
  <p>The true history of the
composition of the poem is this: “Antony and Cleopatra”
was written at the Lytle homestead in the summer of 1858.
The original manuscript was dashed off in a glow
of creative excitement by the author, who left it lying upon
a writing table in his private room. There it was found by
Wm. W. Fosdick, [who] gave it to the editor of the <em>Cincinnati Commercial</em> […]
The poem appeared in the <em>Commercial</em> on July 29, 1858.</p>
</blockquote>

<table class="smaller">
<tr><td>I am dying, Egypt, dying!<br />
&emsp;Ebbs the crimson life-tide fast,<br />
And the dark Plutonian shadows<br />
&emsp;Gather on the evening blast;<br />
Let thine arms, O Queen, enfold me,<br />
&emsp;Hush thy sobs and bow thine ear;<br />
Listen to the great heart-secrets<br />
&emsp;Thou, and thou alone, must hear.<span class="pskip"></span><br />
Though my scarr’d and veteran legions<br />
&emsp;Bear their eagles high no more,<br />
And my wreck’d and scatter’d galleys<br />
&emsp;Strew dark Actium’s fatal shore,<br />
Though no glittering guards surround me,<br />
&emsp;Prompt to do their master’s will,<br />
I must perish like a Roman,<br />
&emsp;Die the great Triumvir still.<span class="pskip"></span><br />
[...]<span class="pskip"></span><br />
As for thee, star-eyed Egyptian,<br />
&emsp;Glorious sorceress of the Nile,<br />
Light the path to Stygian horrors<br />
&emsp;With the splendors of thy smile.<br />
Give the Cæsar crowns and arches,<br />
&emsp;Let his brow the laurel twine;<br />
I can scorn the Senate’s triumphs,<br />
&emsp;Triumphing in love like thine.<span class="pskip"></span><br />
I am dying, Egypt, dying;<br />
&emsp;Hark! th’ insulting foeman’s cry.<br />
They are coming! quick, my falchion,<br />
&emsp;Let me front them ere I die.<br />
Ah! no more amid the battle<br />
&emsp;Shall my heart exulting swell;<br />
Isis and Osiris guard thee!<br />
&emsp;Cleopatra, Rome, farewell!
</td></tr>
</table>

<p>The biographer writes: “<em>Antony and Cleopatra</em> is the author’s masterpiece,
but not by any means his only good poem.” True enough.</p>

<p>John Albro, in <em>Puck</em> (1882-11-01),
<a href="https://archive.org/details/sim_puck_1882-11-01_12_295/page/n2">writes</a>, “Take Your Choice”:</p>

<table class="smaller">
<tr><td>I am dying, Egypt, dying,<br />
&emsp;Which I'm barely just alive<br />
From exhaustive efforts trying<br />
&emsp;To pronounce that word “<a href="https://en.wikipedia.org/wiki/Anglo-Egyptian_War">Khedive</a>.”<span class="pskip"></span><br />
Are they lying, Egypt, lying,<br />
&emsp;Who assert we should receive<br />
"I" as "e"? And are they guying<br />
&emsp;When they call the cuss “Khedeve”?<span class="pskip"></span><br />
I am crying, Egypt, crying:<br />
&emsp;Orthographical contriver,<br />
In the face of English flying,<br />
&emsp;Won't it do to say “Khediver”?<span class="pskip"></span><br />
I am sighing, Egypt, sighing,<br />
&emsp;For my girl—can I believe her<br />
When she's twisting, when she's tying<br />
&emsp;Her sweet tongue into “Khedever”?<span class="pskip"></span><br />
I am nighing, Egypt, nighing<br />
&emsp;My <i>finale</i>. Ere ’tis over—<br />
Ere I’m frying, Egypt, frying—<br />
&emsp;I would fain suggest “Khedover.”
</td></tr>
</table>

<p>And the Chicago <em>Tribune</em> of 1889-06-02
<a href="https://archive.org/details/per_chicago-daily-tribune_the-chicago-tribune_1889-06-02_49/page/n30/mode/1up">has</a>:</p>

<table class="smaller">
<tr><td>I am lying, Egypt, lying, in my own peculiar way,<br />
I acquired the habit lately, but I do it every day;<br />
Every morning to the river with my tackle I repair<br />
To beguile the speckled troutlet from its cool, pellucid lair.<br />
In the evening, on returning, I describe my victim's size,<br />
And I'm roaming, Egypt, roaming in a wilderness of lies.
</td></tr>
</table>

<p>The “speckled troutlet” is perhaps borrowed
from Louisa J. Roberts’ <a href="https://archive.org/details/biographicalske00robegoog/page/n273">“The Angler”</a>:
“To such cool shade, such limpid brook, / The angler comes with line and hook, / To tempt with his
enticing fly / The speckled troutlet whisking by.”</p>

<p>I got onto this track after finding <a href="https://www.nyshistoricnewspapers.org/?a=d&amp;d=tew19080728-01.1.11">a somewhat bit-rotted version</a>
of that last poem in the New York <em>World</em> of 1908-07-28.
The same day’s <em>World</em>, <a href="https://www.nyshistoricnewspapers.org/?a=d&amp;d=tew19080728-01.1.12">page 12</a>,
reports that heavyweight <a href="https://en.wikipedia.org/wiki/Gus_Ruhlin">Gus Ruhlin</a> put up $500 bail each
for several men rounded up at an illicit boxing match, including one
“<a href="https://en.wikipedia.org/wiki/Rube_Goldberg">Reuben Goldberg</a>, cartoonist.” According to
<a href="https://www.tcj.com/a-konversation-with-george-herrimans-biographer-michael-tisserand-part-two/">The Comics Journal</a>,
Goldberg had been acting as timekeeper.</p>

<hr />

<p>I was leafing through the <em>World</em> because Robert Anton Wilson
<a href="https://archive.org/details/cosmic-trigger-vol.-1/page/92">had written</a>
(in <em>Cosmic Trigger Vol. I</em>, 1977) that Charles Fort
<a href="https://archive.org/details/bwb_S0-ADE-388/page/863">had written</a>
(in <em>Wild Talents</em>, 1932) that
the 1908-07-29 <em>World</em> contained a story about a large black dog
walking up to two police detectives in Pittsburgh, emitting a hearty
“Good morning,” and vanishing in a puff of greenish vapor.
In fact it does not. It can be nothing but coincidence that Wilson
misquotes Fort’s source as “the <em>New York World</em>, July 2<b>7</b>, 1908,”
which <em>does</em> contain something of the sort, on page 8, under the headline
“The Wonderful Talking Dog.” Paraphrased:</p>

<blockquote>
  <p>A penniless ventriloquist and his dog walk into a restaurant.
“What’ll you have?” says the proprietor. The ventriloquist cocks his head
at the dog. “I’ll have a ham sandwich,” it says. The proprietor is amazed at
the talking dog, and offers to buy it for $50 above and beyond the cost of the
meal. Of course the ventriloquist accepts. As he’s leaving, full and flush,
he glances back at the dog he left behind: “You bum,” it yells, “to sell me for $50!
I’ll show you — I’ll never speak another word!” …And it never did.</p>
</blockquote>]]></content><author><name></name></author><category term="jokes" /><category term="old-shit" /><category term="poetry" /><summary type="html"><![CDATA[The biographer of [William Haines Lytle](https://en.wikipedia.org/wiki/William_Haines_Lytle) writes, of his poem ["Antony and Cleopatra"](https://archive.org/details/poemsofwilliamha00lytl/page/60/mode/2up): > Bryant's "Library of Poetry and Song" is held responsible for > having first put into circulation the absurd fiction that Lytle's > famous poem was written while the author lay mortally wounded > after the battle of Chickamauga.]]></summary></entry><entry><title type="html">C’s designated initializers give us named arguments</title><link href="https://quuxplusone.github.io/blog/2026/11/16/named-arguments-in-c/" rel="alternate" type="text/html" title="C’s designated initializers give us named arguments" /><published>2026-11-16T00:01:00+00:00</published><updated>2026-11-16T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/11/16/named-arguments-in-c</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/11/16/named-arguments-in-c/"><![CDATA[<p>In my <a href="/blog/2026/11/10/designated-or-lambda/">previous post</a>
I talked about C++’s “relatively nerfed” form of designated initializers.
This time I want to show you a neat thing you can do with C’s full-power designated
initializers. I first saw this pattern in Ben Klemens’ book <a href="https://link.amazon/B01S8VI8a"><em>21st Century C</em></a> (2014),
pages 226–228. (<a href="https://godbolt.org/z/sq9oT4ETr">Godbolt.</a>)</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct IdealVolumeArgs {
  double atm;      // P
  double moles;    // n
  double kelvin;   // T
};
#define ideal_volume(...) ideal_volume_impl( \
  (struct IdealVolumeArgs){ \
    .atm=1, .moles=1, .kelvin=273.15, __VA_ARGS__ \
  })
double ideal_volume_impl(struct IdealVolumeArgs args) {
  // The ideal gas law: PV = nRT
  return args.moles * 0.082057366 * args.kelvin / args.atm;
}

int main() {
  printf("1 mole of gas at STP occupies %g L\n",
    ideal_volume());
  printf("1 mole of gas at 100°C occupies %g L\n",
    ideal_volume(.kelvin = 373.15));
  printf("2 moles of gas at 100°C occupies %g L\n",
    ideal_volume(.kelvin = 373.15, .moles = 2));
  printf("2 moles of gas at 0°C and 2 atm occupies %g L\n",
    ideal_volume(.moles = 2, .atm = 2));
}
</code></pre></div></div>

<p>This idiom gives us named, defaultable arguments with natural function-call syntax.
It relies on two features of C’s designated initializers that C++20 didn’t adopt:</p>

<ul>
  <li>
    <p>They can appear in any order: <code class="language-plaintext highlighter-rouge">(struct IdealVolumeArgs){ .atm=1, .moles=2 }</code> means
  the same thing as <code class="language-plaintext highlighter-rouge">(struct IdealVolumeArgs){ .moles=2, .atm=1 }</code>.</p>
  </li>
  <li>
    <p>The same designator can appear multiple times, and only the last one “sticks”:
  <code class="language-plaintext highlighter-rouge">(struct IdealVolumeArgs){ .atm=1, .moles=2, .atm=3 }</code> means the same thing
  as <code class="language-plaintext highlighter-rouge">(struct IdealVolumeArgs){ .atm=3, .moles=2 }</code>.</p>
  </li>
</ul>

<blockquote>
  <p>That second bullet means we’re relying on something that would be bad style if it
weren’t intentional. Clang emits a <nobr><code>-Winitializer-overrides</code></nobr> diagnostic by default.
GCC (more sensibly IMHO) emits <nobr><code>-Woverride-init</code></nobr> only with <nobr><code>-Wextra</code>.</nobr></p>
</blockquote>

<p>Once a function uses this idiom, adding a new named parameter to the function definition
is no longer an API break! For example, we might decide to
let the caller provide their own value for the ideal gas constant <em>R</em>. We simply add a new
field to the <code class="language-plaintext highlighter-rouge">Args</code> struct. All the old call-sites will still compile just fine, and have the
same behavior. (It’s not an API break, but it <em>is</em> an <em>ABI</em> break: the callers needn’t be
re-<i>written</i>, but they do need to be re-<i>compiled</i> against the new header.)</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct IdealVolumeArgs {
  double atm;      // P
  double moles;    // n
  double R;        // R -- this new field changes ABI
  double kelvin;   // T
};
#define ideal_volume(...) ideal_volume_impl((struct IdealVolumeArgs){ \
  .atm=1, .moles=1, .R = 0.082057366, .kelvin=273.15, __VA_ARGS__ \
})
double ideal_volume_impl(struct IdealVolumeArgs args) {
  return args.moles * args.R * args.kelvin / args.atm;
}
</code></pre></div></div>

<p>If you’re writing a family of related functions, you can share the <code class="language-plaintext highlighter-rouge">Args</code> struct among
the whole family; for example, we might add a <code class="language-plaintext highlighter-rouge">.liters</code> field to our struct, rename it
<code class="language-plaintext highlighter-rouge">IdealGasArgs</code>, and define a whole family of functions using that bag of keyword arguments:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#define ideal_pressure(...) ideal_pressure_impl((struct IdealGasArgs){ \
  .atm=NAN, .moles=1, .kelvin=273.15, .liters=1, __VA_ARGS__ })
#define ideal_amount(...) ideal_amount_impl((struct IdealGasArgs){ \
  .atm=1, .moles=NAN, .kelvin=273.15, .liters=1, __VA_ARGS__ })
#define ideal_temperature(...) ideal_temperature_impl((struct IdealGasArgs){ \
  .atm=1, .moles=1, .kelvin=NAN, .liters=1, __VA_ARGS__ })
</code></pre></div></div>

<p>You can also prepend any number of non-keyword arguments:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>typedef struct { int cx, cy, r; } CircleArgs;
void sc_circle_impl(ScreenContext *, int opcode, CircleArgs);
#define sc_erase_circle(sc, ...) sc_circle_impl(sc, 0, (CircleArgs){__VA_ARGS__})
#define sc_draw_circle(sc, ...)  sc_circle_impl(sc, 1, (CircleArgs){__VA_ARGS__})
#define sc_fill_circle(sc, ...)  sc_circle_impl(sc, 2, (CircleArgs){__VA_ARGS__})
</code></pre></div></div>

<h2 id="usage-in-the-wild">Usage in the wild</h2>

<p>Should you go out and replace all your ordinary C code with this pattern? Absolutely not.
It’s heavyweight, and “cute,” compared to just writing an ordinary non-named-argument function like</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>double ideal_volume(double atm, double moles, double kelvin) {
  return moles * 0.082057366 * kelvin / atm;
}
</code></pre></div></div>

<p>which almost invariably is all you need. Still, a quick regex search of GitHub turns up
a few real-looking uses of the pattern. The first shareworthy use I found was in
<a href="https://github.com/gab462/hof-flecs-raylib/blob/5abf44930b4ddc92178749d82561ce3e5cc3a0cb/include/message.h#L97">gab462/hof-flecs-raylib</a>,
which uses it to write calls
<a href="https://github.com/gab462/hof-flecs-raylib/blob/5abf44930b4ddc92178749d82561ce3e5cc3a0cb/src/client/systems.c#L175">such as</a></p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>send_message(&amp;globals.send_buf, msg, .from_id = globals.name);
</code></pre></div></div>

<p>The most high-profile project in which I found this pattern was
<a href="https://github.com/EpicGames/raddebugger/blob/5b0d5f67a46af5fffa52322e95a116dabf393103/src/ui/ui_core.h#L955-L956">EpicGames/raddebugger</a>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>typedef struct UI_AnimParams UI_AnimParams;
struct UI_AnimParams {
  F32 initial;
  F32 target;
  F32 rate;
  F32 epsilon;
  B32 reset;
};
internal F32 ui_anim_(UI_Key key, UI_AnimParams *params);
#define ui_anim(key, target_val, ...) ui_anim_((key), &amp;(UI_AnimParams){.target = (target_val), .rate = (ui_state-&gt;default_animation_rate), __VA_ARGS__})
~~~~
F32 cursor_pixel_off__animated = ui_anim(ui_key_from_stringf(~~~~), cursor_pixel_off, .initial = cursor_pixel_off);
~~~~
u-&gt;alive_t = ui_anim(ui_key_from_stringf(~~~~), 1.f, .rate = entity_alive_t_rate);
</code></pre></div></div>]]></content><author><name></name></author><category term="abi" /><category term="designated-initializers" /><category term="library-design" /><category term="pearls" /><category term="preprocessor" /><summary type="html"><![CDATA[In my previous post I talked about C++’s “relatively nerfed” form of designated initializers. This time I want to show you a neat thing you can do with C’s full-power designated initializers. I first saw this pattern in Ben Klemens’ book 21st Century C (2014), pages 226–228. (Godbolt.)]]></summary></entry><entry><title type="html">Fun with designated initializers</title><link href="https://quuxplusone.github.io/blog/2026/11/10/designated-or-lambda/" rel="alternate" type="text/html" title="Fun with designated initializers" /><published>2026-11-10T00:01:00+00:00</published><updated>2026-11-10T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/11/10/designated-or-lambda</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/11/10/designated-or-lambda/"><![CDATA[<p>C++20 (via <a href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0329r4.pdf">P0329</a>)
introduced a relatively nerfed form of designated-initializer (<code class="language-plaintext highlighter-rouge">.field = 42</code>) syntax.
Unlike C, C++20 doesn’t support out-of-order initializers, any mixture of designated
and non-designated initializers, or array-element designators.</p>

<p>Array-element designators like <code class="language-plaintext highlighter-rouge">[0] = 42</code> aren’t supported by standard C++. Why not?
Read the spoiler in <a href="https://eel.is/c++draft/diff.dcl#10.sentence-4">[diff.dcl]</a>,
or, consider Clang’s behavior on the following program
(<a href="https://godbolt.org/z/f4Psq38j7">Godbolt</a>).</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bool oldstyle() {
  #define ZERO 0
  std::any a[3] = {
    [ZERO] {},
  };
  return a[0].has_value(); // false
}

bool modernized() {
  constexpr int zero = 0;
  std::any b[3] = {
    [zero] {},
  };
  return b[0].has_value(); // true
}
</code></pre></div></div>

<p>Spoiler: Clang treats <code class="language-plaintext highlighter-rouge">[0]{}</code> as a C99-style designated initializer for an array element,
using a kind of uniform-initialization style: “Initialize element 0 from this bag of
constructor arguments (which happens to be empty.”
But Clang rightly treats <code class="language-plaintext highlighter-rouge">[zero]{}</code> as a lambda-expression capturing the local variable
<code class="language-plaintext highlighter-rouge">zero</code>, omitting the parameter list (which is legal, though I wish it weren’t!),
and having an empty body. (That’s legal C++: all compilers <em>must</em> parse it that way!)</p>

<p>Ironically, GCC — which originally introduced the designated-initializer extension —
has never supported Clang’s <code class="language-plaintext highlighter-rouge">=</code>-less syntax in C++ mode; although GCC <em>in C mode only</em>
does support a <code class="language-plaintext highlighter-rouge">=</code>-less syntax described in the manual as “obsolete since GCC 2.5.”</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>// in GNU C only
int i[3] = { [1] 42 };
struct A {};
struct A a[3] = { [1] {} };
</code></pre></div></div>

<p>Clang supports that syntax in both C and C++ modes. In C++ mode, the initialization
of <code class="language-plaintext highlighter-rouge">i</code> gives <code class="language-plaintext highlighter-rouge">-Wgnu-designator</code>, but (since Clang 10) the initialization of <code class="language-plaintext highlighter-rouge">a</code> doesn’t.
(<a href="https://godbolt.org/z/93hWszd56">Godbolt.</a>)</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>warning: use of GNU 'missing =' extension in designator [-Wgnu-designator]
    3 | int i[3] = { [1] 42 };

warning: array designators are a C99 extension [-Wc99-designator]
    4 | struct A a[3] = { [1] {} };
</code></pre></div></div>

<p>Footnote: As far as I know, even in C, where out-of-order initializers are legal, no compiler
permits array-element initializers whose indices are determined at runtime. You might wish</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>int a[5] = { [argc] = 1 };
</code></pre></div></div>

<p>were equivalent to</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>int a[5] = {};
a[argc] = 1;
</code></pre></div></div>

<p>but in fact both GCC and Clang reject it.</p>

<hr />

<p>See also:</p>

<ul>
  <li><a href="/blog/2026/11/16/named-arguments-in-c/">“C’s designated initializers give us named arguments”</a></li>
</ul>]]></content><author><name></name></author><category term="contrived-examples" /><category term="designated-initializers" /><category term="implementation-divergence" /><summary type="html"><![CDATA[C++20 (via [P0329](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0329r4.pdf)) introduced a relatively nerfed form of designated-initializer (`.field = 42`) syntax. Unlike C, C++20 doesn't support out-of-order initializers, any mixture of designated and non-designated initializers, or array-element designators. Array-element designators like `[0] = 42` aren't supported by standard C++. Why not? Read the spoiler in [diff.dcl], or, consider Clang's behavior on the following program ([Godbolt](https://godbolt.org/z/f4Psq38j7)).]]></summary></entry><entry><title type="html">_Paradise Lost_, diffed</title><link href="https://quuxplusone.github.io/blog/2026/10/17/paradise-lost-diffed/" rel="alternate" type="text/html" title="_Paradise Lost_, diffed" /><published>2026-10-17T00:01:00+00:00</published><updated>2026-10-17T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/10/17/paradise-lost-diffed</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/10/17/paradise-lost-diffed/"><![CDATA[<p>One of my book clubs will be starting Milton’s <em>Paradise Lost</em> soon.
Preparing for that reading, I learned that there are actually two
different versions of <em>Paradise Lost</em>: the “original” 1667 edition
in ten books, and the 1674 revised edition in twelve.</p>

<p>Are the differences between the two editions as significant as, say,
the differences between the 1818 and 1831 editions of Mary Shelley’s
<em>Frankenstein</em>? To find out, I wanted a website similar to
Eduardo Villuendas’ <a href="https://frankendiff.com/"><em>Frankendiff.com</em></a>.
So, I made one.</p>

<p>Presenting <i><a href="https://quuxplusone.github.io/Wikisource/Milton/paradise-lost-diffed.html">Paradise Lost, Diffed</a>!</i>
Unlike <em>Frankendiff</em>, which was vibe-coded, this page was painstakingly
hand-crafted, starting from <a href="https://www.gutenberg.org/ebooks/20">Project Gutenberg e-text #20</a>
and comparing it to the Internet Archive’s scans of real books from 1668 and 1674.
(This turned up about 106 errata in e-text #20, which I have reported to PG.)
This resulted in a single 531-kilobyte plain HTML page — which sounds gigantic,
but is coincidentally just about the size of <em>Frankendiff</em>’s JavaScript.</p>

<p>The answer, by the way, is “no”: the differences between the ten-book and
twelve-book editions of <em>Paradise Lost</em> are extremely minor. I actually marked
with asterisks in the margin each instance where the difference affects the
sense of the verse; there are only 18, even counting instances like
“<strike>add</strike> <u>and</u> the humble Shrub”
(<a href="https://archive.org/details/paradiselostpoem00milt_1/page/n208">VII.322</a>),
which (1) has basically the same sense and (2) is probably a typographical error
in the first place.</p>

<p><img src="/blog/images/2026-10-17-anakin-milton.jpg" alt="" class="meme" /></p>

<p>As usual with this sort of thing, I’ll offer a bug bounty: if you find
a mistake on that page, <a href="mailto:arthur.j.odwyer@gmail.com">send me an email</a> and
I’ll send you $5. (Per error that you’re the first to report. I expect
these days that someone’ll throw an LLM at it, so let me add an “AI rider”:
if your agent sends me an unwieldy number of suggestions, I reserve the right
to look at them and fix any that are real, but if an obviously LLM-generated
list has more false positives than true positives, you won’t get any bounty.)</p>]]></content><author><name></name></author><category term="litclub" /><category term="memes" /><category term="old-shit" /><category term="poetry" /><category term="transcription" /><category term="web" /><summary type="html"><![CDATA[One of my book clubs will be starting Milton's _Paradise Lost_ soon. Preparing for that reading, I learned that there are actually two different versions of _Paradise Lost_: the “original” 1667 edition in ten books, and the 1674 revised edition in twelve. Are the differences between the two editions as significant as, say, the differences between the 1818 and 1831 editions of Mary Shelley's _Frankenstein_? To find out, I wanted a website similar to Eduardo Villuendas' [_Frankendiff.com_](https://frankendiff.com/). So, I made one. Presenting [Paradise Lost, Diffed](https://quuxplusone.github.io/Wikisource/Milton/paradise-lost-diffed.html)!]]></summary></entry><entry><title type="html">Is a sized random-access range always common?</title><link href="https://quuxplusone.github.io/blog/2026/10/12/sized-random-access-range/" rel="alternate" type="text/html" title="Is a sized random-access range always common?" /><published>2026-10-12T00:01:00+00:00</published><updated>2026-10-12T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/10/12/sized-random-access-range</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/10/12/sized-random-access-range/"><![CDATA[<p><a href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3411r6.html#proposed-design">P3411R6 <code class="language-plaintext highlighter-rouge">any_view</code></a>
proposes for C++29 a design for a type-erased Ranges view. The idea (as usual with type erasure) is
to permit replacing templated code like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>template&lt;std::ranges::range R&gt;
void f(R&amp;&amp; rg) {
  bool b = std::ranges::is_heap(rg, std::greater&lt;&gt;());
  assert(b);
}

int a[] = {1,2,3,4,5};
std::vector&lt;int&gt; v = {1,2,3,4,5};
f(a);
f(v);
f(std::views::iota(1, 6));
f(std::vector&lt;int&gt;{1,2,3,4,5});
</code></pre></div></div>

<p>with non-templated code like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>// This is not a function template!
void g(std::ranges::any_view&lt;int, std::ranges::any_view_options::random_access, int&gt; rg) {
  bool b = std::ranges::is_heap(rg, std::greater&lt;&gt;());
  assert(b);
}

g(a);
g(v);
g(std::views::iota(1, 6));
g(std::vector&lt;int&gt;{1,2,3,4,5});
</code></pre></div></div>

<p>Because there are so many different flavors of range, <code class="language-plaintext highlighter-rouge">any_view</code> takes a few template parameters
to specify what kind of range you mean — just like <code class="language-plaintext highlighter-rouge">std::function</code> takes a function signature as
a template parameter to specify what kind of function you mean. In the example above, we specify
that <code class="language-plaintext highlighter-rouge">g</code> takes a type-erased copy of a <em>random-access</em> view <em>of a range of <code class="language-plaintext highlighter-rouge">int</code></em>. The third template
parameter forces the copy’s <code class="language-plaintext highlighter-rouge">reference</code> type to <code class="language-plaintext highlighter-rouge">int</code> (as opposed to <code class="language-plaintext highlighter-rouge">int&amp;</code> or <code class="language-plaintext highlighter-rouge">const int&amp;</code>), for the
benefit of <code class="language-plaintext highlighter-rouge">views::iota</code>.</p>

<p><code class="language-plaintext highlighter-rouge">any_view</code> inherits from <code class="language-plaintext highlighter-rouge">std::ranges::view_interface,</code> so it gets many convenient
member functions for free. For example,</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>using enum std::ranges::any_view_options;
void g(std::ranges::any_view&lt;int, random_access, int&gt; rg) {
  assert(rg.front() == 1);
}
</code></pre></div></div>

<p>because <code class="language-plaintext highlighter-rouge">view_interface</code> provides <a href="https://en.cppreference.com/cpp/ranges/view_interface/front"><code class="language-plaintext highlighter-rouge">front</code></a>
whenever its iterator category is forward-or-better.
Recently on <a href="https://lists.isocpp.org/std-proposals/2026/10/19191.php">std-proposals</a> it was
noted that <code class="language-plaintext highlighter-rouge">back</code> is different:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>void h(std::ranges::any_view&lt;int, random_access | sized, int&gt; rg) {
  assert(rg.back() == 5);  // error
}
</code></pre></div></div>

<p>You might think <code class="language-plaintext highlighter-rouge">rg.back()</code> would be defined as equivalent to <code class="language-plaintext highlighter-rouge">rg[rg.size()-1]</code> — perfectly
well-defined for a <em>sized random-access</em> range as we have here — but in fact it’s defined as
<code class="language-plaintext highlighter-rouge">*prev(rg.end())</code>, which is well-defined only for <em>common bidirectional</em> ranges. (Recall that a <em>common</em> range
is one where <code class="language-plaintext highlighter-rouge">end()</code> returns the same iterator type as <code class="language-plaintext highlighter-rouge">begin()</code>, so that <code class="language-plaintext highlighter-rouge">prev(end())</code> is legal. For a general,
non-common, range, <code class="language-plaintext highlighter-rouge">end()</code> is allowed to return a sentinel that doesn’t support arithmetic.)</p>

<hr />

<p>The problem is already addressed inside the <code class="language-plaintext highlighter-rouge">views::common</code> adaptor itself. Ordinarily, to make a non-common
range into a <code class="language-plaintext highlighter-rouge">common_view</code>, you basically have to turn every iterator into a variant — a
<a href="https://eel.is/c++draft/iterators.common"><code class="language-plaintext highlighter-rouge">common_iterator&lt;I, S&gt;</code></a> — that can hold either an iterator
<em>or</em> a sentinel, and you represent <code class="language-plaintext highlighter-rouge">views::common(rg).end()</code> as <code class="language-plaintext highlighter-rouge">common_iterator&lt;I, S&gt;(rg.end())</code>.
Since a <code class="language-plaintext highlighter-rouge">common_iterator</code> value might hold a sentinel, <code class="language-plaintext highlighter-rouge">common_iterator</code> itself can’t support decrement;
it is always at best a forward iterator. <em>But,</em> in the special case where <code class="language-plaintext highlighter-rouge">rg</code> is a sized random-access range,
<code class="language-plaintext highlighter-rouge">views::common(rg)</code> does <em>not</em> use <code class="language-plaintext highlighter-rouge">common_iterator</code>: in that case <code class="language-plaintext highlighter-rouge">views::common(rg).end()</code> is represented
as <code class="language-plaintext highlighter-rouge">rg.begin() + rg.size()</code>. <a href="https://godbolt.org/z/W9rjxh93f">Godbolt</a>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct UnsizedRA {
  int *begin();
  std::unreachable_sentinel_t end();
};
UnsizedRA r1;
std::forward_iterator auto it1 = std::views::common(r1).begin();
static_assert(sizeof(it1) &gt; sizeof(int*));

struct SizedRA {
  int *begin();
  std::unreachable_sentinel_t end();
  int size() const;
};
SizedRA r2;
std::same_as&lt;int*&gt; auto it2 = std::views::common(r2).begin();
</code></pre></div></div>

<p>So, from the C++ user’s perspective, the way to deal with the absence of <code class="language-plaintext highlighter-rouge">any_view::back()</code>
in this odd corner case is simply to feed your sized random-access <code class="language-plaintext highlighter-rouge">any_view</code> to <code class="language-plaintext highlighter-rouge">views::common</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>void h(std::ranges::any_view&lt;int, random_access | sized, int&gt; rgin) {
  auto rg = std::views::common(std::move(rgin));
  static_assert(std::random_access_range&lt;decltype(rg)&gt;);
  static_assert(std::sized_range&lt;decltype(rg)&gt;);
  assert(rg.back() == 5);  // OK
}
</code></pre></div></div>

<hr />

<p><a href="https://cplusplus.github.io/LWG/issue4003">LWG 4003</a> asked whether we should “improve” the
definition of <code class="language-plaintext highlighter-rouge">view_interface::back()</code> so that it’d work if <em>either</em> of the expressions
<code class="language-plaintext highlighter-rouge">*prev(rg.end())</code> or <code class="language-plaintext highlighter-rouge">rg[rg.size()-1]</code> were valid. However, that direction was rejected, because
it was rightly pointed out that while this would solve the inconsistency in the API of <code class="language-plaintext highlighter-rouge">view_interface</code>
(and therefore <code class="language-plaintext highlighter-rouge">any_view</code>), it wouldn’t solve the basic inconsistency that right now the C++ user
can create a range type (like <code class="language-plaintext highlighter-rouge">SizedRA</code> above) that is</p>

<ul>
  <li>random-access,</li>
  <li>sized,</li>
  <li>but not common.</li>
</ul>

<p>Unfortunately, the library can’t exactly <em>forbid</em> such a type. At best it could amend some concept
definitions so that <code class="language-plaintext highlighter-rouge">SizedRA</code> would fail to be a <code class="language-plaintext highlighter-rouge">sized_range</code> — but that seems silly, because
<code class="language-plaintext highlighter-rouge">SizedRA</code> definitely <em>does</em> provide <code class="language-plaintext highlighter-rouge">size()</code>, and failing to recognize that fact would just
silently pessimize a bunch of Ranges algorithms.</p>

<blockquote>
  <p>I have the same pet peeve about <code class="language-plaintext highlighter-rouge">random_access_range</code>’s requiring <code class="language-plaintext highlighter-rouge">operator[]</code>. If you forget
to provide it, then your type just quietly degrades to a bidirectional range, pessimizing
some algorithms but not necessarily failing to compile.</p>
</blockquote>

<p>Alternatively — but this is a crazy idea — the library might amend the definition of
<a href="https://eel.is/c++draft/range.access#end"><code class="language-plaintext highlighter-rouge">ranges::end(rg)</code></a> to return a different type in this case,
so that <code class="language-plaintext highlighter-rouge">SizedRA</code> would become a common range! Given the current wording:</p>

<blockquote>
  <p>Given a subexpression E with type <code class="language-plaintext highlighter-rouge">T</code>, let <code class="language-plaintext highlighter-rouge">t</code> be an lvalue that denotes the reified object for <code class="language-plaintext highlighter-rouge">E</code>. Then:</p>
  <ul>
    <li>[…] if <code class="language-plaintext highlighter-rouge">T</code> is an array type, <code class="language-plaintext highlighter-rouge">ranges::end(E)</code> is expression-equivalent to <code class="language-plaintext highlighter-rouge">t + extent_v&lt;T&gt;</code>.</li>
    <li>Otherwise, if <code class="language-plaintext highlighter-rouge">auto(t.end())</code> is a valid expression whose type models <code class="language-plaintext highlighter-rouge">sentinel_for&lt;iterator_t&lt;T&gt;&gt;</code>, then <code class="language-plaintext highlighter-rouge">ranges::end(E)</code> is expression-equivalent to <code class="language-plaintext highlighter-rouge">auto(t.end())</code>.</li>
    <li>Otherwise, if <code class="language-plaintext highlighter-rouge">T</code> is a class or enumeration type and <code class="language-plaintext highlighter-rouge">auto(end(t))</code> is a valid expression
  whose type models <code class="language-plaintext highlighter-rouge">sentinel_for&lt;iterator_t&lt;T&gt;&gt;</code> […] then <code class="language-plaintext highlighter-rouge">ranges::end(E)</code> is expression-equivalent to that expression.</li>
  </ul>
</blockquote>

<p>we might remove the first bullet point and then add one at the end like:</p>

<ul>
  <li>[…] if <code class="language-plaintext highlighter-rouge">ranges::begin(t) + ranges::size(t)</code> is a valid expression whose type
  is <code class="language-plaintext highlighter-rouge">iterator_t&lt;T&gt;</code>, then <code class="language-plaintext highlighter-rouge">ranges::end(E)</code> is expression-equivalent to that expression.</li>
</ul>

<p>I say “remove the first” because <code class="language-plaintext highlighter-rouge">ranges::size(t)</code> is already equivalent to <code class="language-plaintext highlighter-rouge">extent_v&lt;T&gt;</code> when <code class="language-plaintext highlighter-rouge">T</code> is an array type;
this amendment would just generalize the array case. Core-language arrays are already a kind of type
that provide a <code class="language-plaintext highlighter-rouge">begin</code> (sort of) but no iterator-returning <code class="language-plaintext highlighter-rouge">end</code> (in fact, no <code class="language-plaintext highlighter-rouge">end</code> at all); this amendment
would handle other kinds of ranges that provide a <code class="language-plaintext highlighter-rouge">begin</code> but no iterator-returning <code class="language-plaintext highlighter-rouge">end</code>.</p>

<p>I say “add one at the end” because <a href="https://eel.is/c++draft/range.access#range.prim.size-2.5"><code class="language-plaintext highlighter-rouge">ranges::size</code></a> itself
already has a bullet point defining <code class="language-plaintext highlighter-rouge">ranges::size(rg)</code> in terms of <code class="language-plaintext highlighter-rouge">ranges::end(rg) - ranges::begin(rg)</code>, and
we don’t want a circular dependency there. The bullet point in <code class="language-plaintext highlighter-rouge">ranges::size</code> basically enforces that any
<em>random-access common</em> range is by definition <em>sized</em> (as long as you go through <code class="language-plaintext highlighter-rouge">ranges::size</code> instead of <code class="language-plaintext highlighter-rouge">t.size()</code>);
the proposed bullet point here would enforce that any <em>random-access sized</em> range is by definition <em>common</em>
(as long as you go through <code class="language-plaintext highlighter-rouge">ranges::end</code> instead of <code class="language-plaintext highlighter-rouge">t.end()</code>).</p>

<p>One obvious problem — and I bet there are also less obvious ones — is that the amendment above would make</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct NotCurrentlyARange {
  int *begin();
  int size();
};
</code></pre></div></div>

<p>into a Ranges <code class="language-plaintext highlighter-rouge">range</code>, even though it wouldn’t be iterable by a core-language <code class="language-plaintext highlighter-rouge">for</code>-loop. The
mismatch between core-language ranges and library Ranges is already arguably a problem: see
<a href="/blog/2024/12/09/foreach-versus-for/">“When <code class="language-plaintext highlighter-rouge">ranges::for_each</code> behaves differently from <code class="language-plaintext highlighter-rouge">for</code>”</a> (2024-12-09).
Let’s not make the existing problem worse!</p>

<hr />

<p>Since piping a sized random-access range through <code class="language-plaintext highlighter-rouge">views::common</code> already Does The Right Thing, and since
trying to use <code class="language-plaintext highlighter-rouge">back()</code> on an <code class="language-plaintext highlighter-rouge">any_view</code> is already a super niche problem, I’m inclined to think the
status quo is perfectly acceptable. But, at the same time, since we can’t forbid types like <code class="language-plaintext highlighter-rouge">SizedRA</code> at the language level,
and since trying to “fix” them at the level of <code class="language-plaintext highlighter-rouge">ranges::end</code> is crazy, and since <code class="language-plaintext highlighter-rouge">view_interface::back</code>
admittedly doesn’t work quite right… why <em>not</em> just fix <code class="language-plaintext highlighter-rouge">view_interface::back</code> in the way
<a href="https://cplusplus.github.io/LWG/issue4003">LWG 4003</a> originally proposed?</p>]]></content><author><name></name></author><category term="library-design" /><category term="proposal" /><category term="ranges" /><category term="type-erasure" /><summary type="html"><![CDATA[P3411R6 any_view proposes for C++29 a design for a type-erased Ranges view. The idea (as usual with type erasure) is to permit replacing templated code like this:]]></summary></entry><entry><title type="html">Recursive `make` and `-j`</title><link href="https://quuxplusone.github.io/blog/2026/09/30/recursive-make-j/" rel="alternate" type="text/html" title="Recursive `make` and `-j`" /><published>2026-09-30T00:01:00+00:00</published><updated>2026-09-30T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/09/30/recursive-make-j</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/09/30/recursive-make-j/"><![CDATA[<p>Today I looked into “recursive” invocations of <code class="language-plaintext highlighter-rouge">make</code>; that is, cases in which a Makefile
recipe itself invokes <code class="language-plaintext highlighter-rouge">make</code>.
<a href="https://www.gnu.org/software/make/manual/make.html#Recursion">The official documentation</a>
is quite good, but since I’m working with a range of different GNU Make versions, I looked
at how the behavior has changed over time, from GNU Make 3.81 to 4.3.</p>

<p>Basically, the issue is that if you have a recipe in your Makefile like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ser:
    make -C subdir
</code></pre></div></div>

<p>and then you run <code class="language-plaintext highlighter-rouge">make -j4 ser</code>, recent versions of GNU Make will give a warning
(<code class="language-plaintext highlighter-rouge">jobserver unavailable: using -j1</code>). And you’ll lose the parallelism you wanted,
because the “jobserver” (basically, the <code class="language-plaintext highlighter-rouge">-j</code> option) isn’t forwarded to the child <code class="language-plaintext highlighter-rouge">make</code>.
And, incidentally, it won’t necessarily use the same <code class="language-plaintext highlighter-rouge">make</code> binary that <em>you</em> invoked;
it’ll run whatever <code class="language-plaintext highlighter-rouge">make</code> happens to be in your path.</p>

<p>You can fix all three of those issues by prefixing <code class="language-plaintext highlighter-rouge">+</code> to the recipe line,
or (since that feels uncomfortably magical) replacing <code class="language-plaintext highlighter-rouge">make</code> with <code class="language-plaintext highlighter-rouge">$(MAKE)</code>.
More on this at the end of the post. Now that we’re forwarding the “jobserver”
properly, I wondered, how <em>exactly</em> do the various <code class="language-plaintext highlighter-rouge">-j</code> options interact,
when you specify one degree of parallelism on the command line and another
in the recursive recipe?</p>

<p>Here’s the pair of Makefiles I used for my test:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>detab -E -4 - &gt;Makefile &lt;&lt;EOF
ser:
    make -C subdir
par2:
    make -j2 -C subdir
par4:
    make -j4 -C subdir
par:
    make -j -C subdir
serplus:
    +make -C subdir
par2plus:
    +make -j2 -C subdir
par4plus:
    +make -j4 -C subdir
parplus:
    +make -j -C subdir
sermake:
    $(MAKE) -C subdir
par2make:
    $(MAKE) -j2 -C subdir
par4make:
    $(MAKE) -j4 -C subdir
parmake:
    $(MAKE) -j -C subdir
EOF
mkdir subdir
detab -E -4 - &gt;subdir/Makefile &lt;&lt;EOF
all: one two three four five
one:
    echo 'one' &amp;&amp; sleep 1 &amp;&amp; echo 'ONE'
two:
    echo 'two' &amp;&amp; sleep 1 &amp;&amp; echo 'TWO'
three:
    echo 'thr' &amp;&amp; sleep 1 &amp;&amp; echo 'THR'
four:
    echo 'fou' &amp;&amp; sleep 1 &amp;&amp; echo 'FOU'
five:
    echo 'fiv' &amp;&amp; sleep 1 &amp;&amp; echo 'FIV'
EOF
</code></pre></div></div>

<p>Then I tested running <code class="language-plaintext highlighter-rouge">make ser</code>, <code class="language-plaintext highlighter-rouge">make -j2 ser</code>, etc., on
various versions of Make available to me.</p>

<p>Here’s GNU Make 3.81 (on OS X). The number in each cell indicates
the number of recipes running in parallel. The four rows marked with a dagger †
differ among the versions of Make I tested; those idioms are
“non-portable” and IMHO should be avoided in practice.</p>

<table>
  <thead>
    <tr>
      <th><code class="language-plaintext highlighter-rouge">make</code>…</th>
      <th> </th>
      <th><code class="language-plaintext highlighter-rouge">-j2</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j4</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j</code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ser</code><sup>†</sup></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">serplus</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">sermake</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2plus</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2make</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4plus</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4make</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par</code><sup>†</sup></td>
      <td>∞</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parplus</code><sup>†</sup></td>
      <td>∞</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parmake</code><sup>†</sup></td>
      <td>∞</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
  </tbody>
</table>

<p>In the table above, “b” indicates this warning:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ make -j2 par2
make[1]: warning: -jN forced in submake: disabling jobserver mode.
</code></pre></div></div>

<p>GNU Make 4.0 (on Debian 8.11):</p>

<table>
  <thead>
    <tr>
      <th><code class="language-plaintext highlighter-rouge">make</code>…</th>
      <th> </th>
      <th><code class="language-plaintext highlighter-rouge">-j2</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j4</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j</code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ser</code><sup>†</sup></td>
      <td>1</td>
      <td>1<sup>a</sup></td>
      <td>1<sup>a</sup></td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">serplus</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">sermake</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2plus</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2make</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4plus</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4make</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par</code><sup>†</sup></td>
      <td>∞</td>
      <td>1<sup>a</sup></td>
      <td>1<sup>a</sup></td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parplus</code><sup>†</sup></td>
      <td>∞</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parmake</code><sup>†</sup></td>
      <td>∞</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
  </tbody>
</table>

<p>In the table above, “a” and “b” indicate these two warnings, respectively:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ make -j2 ser
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.

$ make -j2 par2
make[1]: warning: -jN forced in submake: disabling jobserver mode.
</code></pre></div></div>

<p>GNU Make 4.2.1 (on Rocky 8.10) and GNU Make 4.3 (on Red Hat 9 or Ubuntu 22.04)
tweak the latter error message to include the value of <code class="language-plaintext highlighter-rouge">N</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ make -j2 par
make[1]: warning: -j0 forced in submake: resetting jobserver mode.
$ make -j2 par2
make[1]: warning: -j2 forced in submake: resetting jobserver mode.
</code></pre></div></div>

<p>and also change the behavior of rows <code class="language-plaintext highlighter-rouge">par</code>, <code class="language-plaintext highlighter-rouge">parplus</code>, and <code class="language-plaintext highlighter-rouge">parmake</code>:</p>

<table>
  <thead>
    <tr>
      <th><code class="language-plaintext highlighter-rouge">make</code>…</th>
      <th> </th>
      <th><code class="language-plaintext highlighter-rouge">-j2</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j4</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j</code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ser</code><sup>†</sup></td>
      <td>1</td>
      <td>1<sup>a</sup></td>
      <td>1<sup>a</sup></td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">serplus</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">sermake</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2plus</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par2make</code></td>
      <td>2</td>
      <td>2<sup>b</sup></td>
      <td>2<sup>b</sup></td>
      <td>2</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4plus</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4make</code></td>
      <td>4</td>
      <td>4<sup>b</sup></td>
      <td>4<sup>b</sup></td>
      <td>4</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par</code><sup>†</sup></td>
      <td>∞</td>
      <td>∞<sup>b</sup></td>
      <td>∞<sup>b</sup></td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parplus</code><sup>†</sup></td>
      <td>∞</td>
      <td>∞<sup>b</sup></td>
      <td>∞<sup>b</sup></td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">parmake</code><sup>†</sup></td>
      <td>∞</td>
      <td>∞<sup>b</sup></td>
      <td>∞<sup>b</sup></td>
      <td>∞</td>
    </tr>
  </tbody>
</table>

<p>Warning “a,” which explicitly tells you to “Add <code class="language-plaintext highlighter-rouge">'+'</code> to parent make rule,” will indeed
always vanish if you prefix the <code class="language-plaintext highlighter-rouge">make</code>-containing line with <code class="language-plaintext highlighter-rouge">+</code>, like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>serplus:
    +make -C subdir
</code></pre></div></div>

<p>I find that solution as uncomfortably magical as <a href="https://www.gnu.org/software/make/manual/make.html#Echoing">prefix <code class="language-plaintext highlighter-rouge">@</code></a>
or <a href="https://www.gnu.org/software/make/manual/make.html#Errors">prefix <code class="language-plaintext highlighter-rouge">-</code></a>.
(Personally, I’d rather see “<code class="language-plaintext highlighter-rouge">|| true</code>” at the end of a recipe line than a magic “<code class="language-plaintext highlighter-rouge">-</code>” at the beginning.)
A solution that’s less magic-looking (although equally magic under the hood, apparently)
is to use <code class="language-plaintext highlighter-rouge">$(MAKE)</code>, like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sermake:
    $(MAKE) -C subdir
</code></pre></div></div>

<p>Neither method silences warning “b,” about “resetting jobserver mode,” though.</p>

<p>What we really want is a row that would look like <code class="language-plaintext highlighter-rouge">fantasy</code> below.
But at the moment, it seems we have to choose our preferred tradeoff from
one of the quoted rows, instead.</p>

<table>
  <thead>
    <tr>
      <th><code class="language-plaintext highlighter-rouge">make</code>…</th>
      <th> </th>
      <th><code class="language-plaintext highlighter-rouge">-j2</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j4</code></th>
      <th><code class="language-plaintext highlighter-rouge">-j</code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">fantasy</code></td>
      <td>nprocs</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">sermake</code></td>
      <td>1</td>
      <td>2</td>
      <td>4</td>
      <td>∞</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">par4make</code></td>
      <td>4</td>
      <td>4b</td>
      <td>4b</td>
      <td>4</td>
    </tr>
  </tbody>
</table>]]></content><author><name></name></author><category term="concurrency" /><category term="makefiles" /><category term="sre" /><summary type="html"><![CDATA[Today I looked into “recursive” invocations of make; that is, cases in which a Makefile recipe itself invokes make. The official documentation is quite good, but since I’m working with a range of different GNU Make versions, I looked at how the behavior has changed over time, from GNU Make 3.81 to 4.3.]]></summary></entry><entry><title type="html">Spelling the type of a “self” parameter with Reflection</title><link href="https://quuxplusone.github.io/blog/2026/09/15/self/" rel="alternate" type="text/html" title="Spelling the type of a “self” parameter with Reflection" /><published>2026-09-15T00:01:00+00:00</published><updated>2026-09-15T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/09/15/self</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/09/15/self/"><![CDATA[<p>Over on <a href="https://lists.isocpp.org/std-proposals/2026/09/19076.php">std-proposals</a>,
it was pointed out that using C++23 “explicit object parameter”
syntax without using <code class="language-plaintext highlighter-rouge">auto</code> (since <code class="language-plaintext highlighter-rouge">auto</code> makes your member function into a
template, changing its semantics) is sometimes cumbersome:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  int i_;
  int f(this MyLengthilyNamedClass self) { return self.i_; }
};
</code></pre></div></div>

<p>You can shorten each member function declaration at the expense of
some repetitive boilerplate up front:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  using Self = MyLengthilyNamedClass;
  int i_;
  int f(this Self self) { return self.i_; }
};
</code></pre></div></div>

<p>Sebastian Wittmeier <a href="https://lists.isocpp.org/std-proposals/2026/09/19076.php">observes</a>
that we can eliminate that boilerplate’s error-prone repetition
of the class name <code class="language-plaintext highlighter-rouge">MyLengthilyNamedClass</code> by using C++26 Reflection:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  using Self = [: std::meta::current_class() :];
  int i_;
  int f(this Self self) { return self.i_; }
};
</code></pre></div></div>

<p>Thibault Ricord-Marchal <a href="https://lists.isocpp.org/std-proposals/2026/09/19116.php">observes</a>
that because the values of defaulted template arguments are evaluated in the context of the “caller,”
rather than where they appear lexically, we can even factor out that boilerplate to the top level:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>template&lt;std::meta::info R = std::meta::current_class()&gt;
using Self = [: R :];

struct MyLengthilyNamedClass {
  int i_;
  int f(this Self&lt;&gt; self) { return self.i_; }
};
</code></pre></div></div>

<p>Now, in these toy examples, I see no reason to prefer any of the above snippets over
the simple idiomatic <em>implicit</em>-object-parameter member function we’ve been writing since
the dawn of time:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  int i_;
  int f() const { return i_; }
};
</code></pre></div></div>

<p>But notice the difference in calling convention. Our first four snippets pass <code class="language-plaintext highlighter-rouge">self</code>
by value, while the ordinary <code class="language-plaintext highlighter-rouge">f() const</code> needs to do a memory load through the <code class="language-plaintext highlighter-rouge">this</code>
pointer. I could just barely imagine a situation where that cost mattered.
(<a href="https://godbolt.org/z/cEWYaoox1">Godbolt.</a>)</p>

<hr />

<p>I imagine one might find other uses for <code class="language-plaintext highlighter-rouge">Self&lt;&gt;</code>. Off the top of my head,
it provides a way to shorten some of the boilerplate of special member functions:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  MyLengthilyNamedClass(const MyLengthilyNamedClass&amp;) = default;
  MyLengthilyNamedClass&amp; operator=(const MyLengthilyNamedClass&amp;) = default;
};
</code></pre></div></div>

<p><a href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2952r2.html">P2952</a>, coming soon
to C++29, will permit <code class="language-plaintext highlighter-rouge">auto</code>’ing the assignment operator’s return type:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  MyLengthilyNamedClass(const MyLengthilyNamedClass&amp;) = default;
  auto&amp; operator=(const MyLengthilyNamedClass&amp;) = default;
};
</code></pre></div></div>

<p>But with <code class="language-plaintext highlighter-rouge">Self&lt;&gt;</code>, you could shorten fully three of the four repetitions (<a href="https://godbolt.org/z/x967o7jGx">Godbolt</a>):</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>struct MyLengthilyNamedClass {
  MyLengthilyNamedClass(const Self&lt;&gt;&amp;) = default;
  Self&lt;&gt;&amp; operator=(const Self&lt;&gt;&amp;) = default;
};
</code></pre></div></div>

<p>I wouldn’t want to see that in my own codebases. But it’s an idea.</p>]]></content><author><name></name></author><category term="explicit-object-parameters" /><category term="reflection" /><category term="pearls" /><summary type="html"><![CDATA[Over on std-proposals, it was pointed out that using C++23 “explicit object parameter” syntax without using auto (since auto makes your member function into a template, changing its semantics) is sometimes cumbersome:]]></summary></entry><entry><title type="html">Color Wheel combinatorics</title><link href="https://quuxplusone.github.io/blog/2026/09/08/color-wheel/" rel="alternate" type="text/html" title="Color Wheel combinatorics" /><published>2026-09-08T00:01:00+00:00</published><updated>2026-09-08T00:01:00+00:00</updated><id>https://quuxplusone.github.io/blog/2026/09/08/color-wheel</id><content type="html" xml:base="https://quuxplusone.github.io/blog/2026/09/08/color-wheel/"><![CDATA[<p>Over the weekend I was introduced to a Looney Labs pyramid game called
<a href="https://www.looneylabs.com/content/color-wheel">“Color Wheel.”</a>
This is a solitaire (or purely cooperative) game similar to
<a href="https://en.wikipedia.org/wiki/Peg_solitaire">peg solitaire</a>. It’s played
on a decagonal 40-space board, with three trios of pyramids in each of
seven colors: 63 pieces total.</p>

<p>After populating the board with 40 random pyramids from the stash such that
no two adjacent pyramids share a color, your goal is to use the fewest moves
to finish the game — where a “move” swaps two pyramids of the same color and/or
size, and the game is “finished” when each color occupies its own contiguous
region of the board.</p>

<p>The official rules encourage you to finish the game within 27 moves, mainly
because the <em>Pyramid Arcade</em> box happens to contain 27 more pyramids, and
you use those to keep score.
If the game had said “within 23 moves,” then you could have used
the 23 leftover colored pyramids to keep score instead.</p>

<p><b>How many possible Color Wheel setups are there in total?</b></p>

<p>A quick Monte Carlo experiment
(<a href="/blog/code/2026-09-08-color-wheel-counter.py">source</a>)
suggests that there are about
\(2.003\times 10^{46}\) distinct Color Wheel setups, up to rotation and reflection.
There are another \(2.195\times 10^{49}\) distinct midgame positions (i.e. positions
flouting setup’s no-color-adjacency criterion). Both kinds of positions
have an average branching factor of roughly 327 (standard deviation about 5).</p>

<p><b>What fraction of Color Wheel setups are solvable within 27 moves? Within 23?</b></p>

<p>I have no idea. Pretty trivially we can observe that every Color Wheel game
must take at least six moves to complete: The game starts with 40 connected components,
and the best possible move replaces 8 components with 2. Five perfect moves
could reduce the number of components to 10, but a solved board has even fewer
(no more than 7).</p>

<blockquote>
  <p>UPDATE, 2026-11-27: A correspondent provides the sketch of a proof that every
Color Wheel game must take at least seven moves to complete. Instead of looking
at the 40 spaces, look at the 50 edges <em>between</em> spaces. Call an edge “monochromatic”
if it separates two pieces of the same color. The game starts with zero monochromatic
edges. A connected component of size \(k\) supplies at least \(k-1\) monochromatic edges,
so a solved board (with at most 7 components) must have at least 33 monochromatic edges.
A six-move solution would touch at most 12 spaces on the board, so it can “monochromify”
only the edges touching those 12 spaces. There are (he wrote) 119,335 sets of 12 spaces
that touch at least 33 edges, and a computer search proves (he wrote) that in none of
those 119,335 cases does “monochromifying” all its edges produce a graph with seven or
fewer connected components. But I did not attempt to reproduce that computer search.</p>
</blockquote>

<p>It’s easy to construct a valid setup that’s solvable in exactly seven moves.</p>

<p><img src="/blog/images/2026-09-08-solvable-in-7.jpg" alt="A configuration solvable in seven moves" /></p>

<p>How about the number of moves that suffices to solve any setup — what’s
<a href="https://mathworld.wolfram.com/GodsNumber.html">God’s Number</a>
for Color Wheel? I’ve got only another trivial observation: the 40 pyramids
on the board can be selection-sorted into any configuration at all using no more
than 39 unconstrained swaps, and any unconstrained swap can be simulated by at most
5 valid moves. (If the pieces match in size, swap them in one move; otherwise, if any
of the six pieces that share color with one and size with the other is on the board,
use three swaps; otherwise, find \(p_1, p_2\) of the same size, \(p_1\) sharing color
with one and \(p_2\) sharing color with the other, and use five swaps.) That gives us
a comically loose upper bound — 195 moves certainly suffice.</p>

<p><b>Challenge: Write a Color Wheel solver.</b></p>

<p>Here’s <a href="/blog/code/2026-09-08-color-wheel-solver.py">a vibe-coded Color Wheel solver</a>
that can do the average board in about 31.3 moves (standard deviation about 3.9).
This is dramatically worse than the rules’ suggestion of 27 moves! Is that more readily
explained by the badness of this solver’s heuristics, or by the conjecture that most
Color Wheel boards are not solvable in 27 moves?</p>

<p>UPDATE, 2026-11-27: A correspondent found a bug in my solver: a loop that accidentally
never ran more than once. Fixing that bug made the solver run about five times as slow,
but improved its mean solution length by about 2.2 moves. Meanwhile, <em>his</em> vibe-coded
solver found a 23-move solution for a board that took my solver 45 moves, and a 21-move
solution for a board that took me 41. So “this solver is bad” is certainly supported
by the evidence.</p>

<p><img src="/blog/images/2026-09-08-old-solver-histogram.png" alt="Histogram of solution lengths found by the buggy solver" /></p>

<p><img src="/blog/images/2026-09-08-new-solver-histogram.png" alt="Histogram of solution lengths found by the fixed solver" /></p>

<p>The Python code that generated those plots was:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>values=[~~~~]
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 2))
plt.hist(values, bins=[x-0.5 for x in range(20, 52)], edgecolor="white", color="#4f81bd")
plt.xticks(range(20, 51, 2))
plt.xlabel("Number of moves taken by my solver")
plt.tight_layout()
plt.show()
</code></pre></div></div>]]></content><author><name></name></author><category term="board-games" /><category term="help-wanted" /><category term="math" /><category term="puzzles" /><summary type="html"><![CDATA[Over the weekend I was introduced to a Looney Labs pyramid game called “Color Wheel.” This is a solitaire (or purely cooperative) game similar to peg solitaire. It’s played on a decagonal 40-space board, with three trios of pyramids in each of seven colors: 63 pieces total.]]></summary></entry></feed>