Name lookup in multiple base classes

Several times people have asked me, “Why does overload resolution not work if the overload set spans two base classes?” That is:

struct Plant {
  void f(int);
struct Fungus {
  void f(int, int);
struct Lichen : Plant, Fungus {
  void g() {
    f(1);     // error, lookup fails
    f(1, 2);  // error, lookup fails

This is because [class.member.lookup] says, essentially, that if we don’t find a declaration of the name f in Lichen’s scope then we should look into its base classes; and if we find declarations of f in more than one base class, we should consider this an unresolvable ambiguity and fail.

Read More

Help wanted: Compile your codebase with P1144 and P2786 relocatability!

At today’s WG21 SG14 (Low Latency) meeting, there was a discussion of P1144 trivial relocatability versus P2786 trivial relocatability. It was remarked that each proposal has a corresponding Clang fork.

So I suggested that anyone interested in relocation could really help us out by downloading both compiler implementations and trying them out on their own codebases! Of course, that means you need to know how to compile them from scratch. Here’s the answer for my P1144 implementation [UPDATE, 2024-04-22:] and for Corentin’s P2786 implementation, as far as I know.

I would love to turn these instructions into Dockerfiles so that you could just build Docker containers containing each Clang, and somehow build your codebase with those Dockerized Clangs. I’ve heard that VS Code actually makes that “easy.” If you do it, I’d love to hear about it. I’ll upload the Dockerfiles here and credit you.

Read More

The Mummy! (1827)

I just finished reading Jane Loudon’s The Mummy!: A Tale of the Twenty-Second Century, a three-volume novel from 1827. I’m fascinated by early science fiction, and the title was irresistible. Turns out the plot is mostly romance — everyone is in love with the wrong people until the very end — and the titular Pharaoh Cheops makes disappointingly few appearances after his electrical reanimation — but the book contains enough futuristic stuff that it’s not totally unrewarding. Here’s a selection of The Mummy! ’s science-fiction bits: consider this a movie trailer aimed at sci-fi fans, with the understanding that (as usual) almost all the good bits are in the trailer, and the trailer is far better than the movie.

Read More

Johnson’s definition of network

In Jane Loudon’s The Mummy!: A Tale of the Twenty-Second Century (1827) — more on that soon — one of the running gags is that due to the success of “universal education,” all the lower-class people speak in learned Latinate phrases, while the average member of the upper class affects (I, 3)

an excessive plainness and simplicity in his language; so much so, indeed, as sometimes almost to degenerate into rudeness, in order that it might be clearly distinguished from the elaborate and scientific expressions of the vulgar.

Read More

Trivial, but not trivially default constructible

I just watched Jason Turner’s CppCon 2023 talk “Great C++ is_trivial.” Circa 41m00s he picks on the wording of [class.prop]/2:

A trivial class is a class that is trivially copyable and has one or more eligible default constructors, all of which are trivial.

“That phrasing’s always bothered me. How can you have more than one default constructor? They could be constrained by requires-clauses… but then not more than one of them is eligible.”

Read More

Ed Catmur’s Triliteral esolang

Prolific C++ contributor Ed Catmur died unexpectedly on a fell run on New Year’s Eve 2023. (Many tributes from the C++ and especially the fell-running community; see e.g. here. He will be missed.) After Ed’s memorial, where a snippet of his CppCon 2023 lightning talk was played, I sifted his GitHub hoping to find the slides from that talk. (It turns out Phil Nash still had them, and they’re now publicly available.) Ed left behind a lot of thought-provoking material. One thing that caught my eye — which I had never known about him — was that he was briefly active on, the wiki for esoteric programming languages.

Read More

Some St. Patrick’s Day math

At today’s Gathering 4 Gardner social, Colm Mulcahy presented on two Irish figures in recreational mathematics with whom Martin Gardner corresponded: Victor Meally and Owen O’Shea. Owen O’Shea is the natural successor to Gardner’s “Professor I.J. Matrix” as a prolific generator of numerological coincidences — see for example The Magic Numbers of the Professor (2007). Victor Meally shows up occasionally in Gardner’s Mathematical Games columns, and also in “Problem 3.14” (appropriate for Pi Day!) in The Colossal Book of Short Puzzles and Problems (2006):

Read More

The 2024 Google Summer of Code idea lists are out

As of late February, Google Summer of Code (GSoC) has published its official list of sponsoring open-source organizations, and each organization has independently published its own list of project ideas. People interested in doing a GSoC project (sort of a summer internship for open source software) should submit a proposal application — the quite short application window is March 18 to April 2.

If you’re a fan of my “trivial relocatability” content, or just want to help relocation’s progress into the mainstream of C++, you might be particularly interested in these three GSoC sponsors:

Read More

Sorting integer_sequence at compile time

The other day I was pointed at this excellent set of template-metaprogramming exercises:

The exercises build gradually, from Prepend and Append, to RemoveFirst and RemoveAll, to Sort. The only things I’d have done differently in that sequence are to include PopFront (which is easier) before PopBack (which, unless I’m missing something, is harder); and include Iota (i.e. std::make_index_sequence) after Length.

Read More

Feature requests for the Auto macro

From time to time readers send me “feature requests” for the Auto scope-guard macro (“The Auto macro” (2018-08-11)). Usually, I say “No need!” The neat thing about Auto’s particular syntax is that it’s conceptually just a way to defer code to the end of a scope. Feature requests usually take the form of modifying the deferred code in some way — which is already (and more explicitly) allowed simply by… writing the code that way.

Read More

Infinite Craft

I’m enjoying the heck out of Neal Agarwal’s web game Infinite Craft. This is a “crafting game” where you start with just four elements and repeatedly combine pairs of elements to create new elements — for example, Water plus Fire equals Steam. The clever gimmick is that instead of hard-coding a finite number of possible combinations, Infinite Craft’s backend (certainly looks as if it) simply asks an LLM what the result ought to be. So the combinations literally never run out.

Read More

A note on feature-test macros

Previously on this blog: “C++2a idioms for library feature detection” (2018-10-26).

Every C++ implementation is required to provide feature-test macros indicating which features it supports. These come in two flavors:

  • Core-language macros such as __cpp_generic_lambdas, specified in [cpp.predefined]. These are provided by the compiler vendor via the same mechanism as __FUNCTION__ and __GNUC__.

  • Library macros such as __cpp_lib_ranges_iota, specified in [version.syn]. These are provided by the library vendor via the same mechanism as assert and _GLIBCXX_RELEASE. They all begin with __cpp_lib_. The easiest way to get all of them at once is to #include <version> (since C++20).

Read More


Over on /r/askmath a couple days ago, “electricmaster23” posed the following puzzle:

Pack the 12 pentominoes into a 6x10 rectangle, then label each cell of that rectangle with a digit from 1 to 5 such that each pentomino contains all of 1 through 5, and, whenever two adjacent cells belong to different pentominoes, their labels’ sum is a prime number.

Read More

What I’m reading lately: Africa, liberty, economics

In December I reread Mike Resnick’s Galactic Comedy, a trilogy of histories of three sci-fi planets based on the 19th- and 20th-century histories of three different African nations. Paradise is based on Kenya (Selous, Jomo Kenyatta, Mau Mau); Purgatory on Zimbabwe (Cecil Rhodes, Kariba Dam, Second Matabele War, Great Zimbabwe); and Inferno on Uganda (Milton Obote, Idi Amin, expulsion of the Asians). I recommend basically everything Mike Resnick ever wrote.

Read More

Should assignment affect is_trivially_relocatable?

Consider the following piece of code that uses Bloomberg’s bsl::vector:

#include <bsl_vector.h>
using namespace BloombergLP::bslmf;

struct T1 {
    int i_;
    T1(int i) : i_(i) {}
    T1(const T1&) = default;
    void operator=(const T1&) { puts("Assigned"); }
    ~T1() = default;

int main() {
    bsl::vector<T1> v = {1,2};

bsl::vector::erase uses T1::operator= to shift element 2 leftward into the position of element 1 (and then destroys the moved-from object in position 2). The program prints “Assigned.”

But that’s because type T1 is not trivially relocatable!

Read More