A priority_tag-like pattern for type-based metaprogramming

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

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

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

How the STL uses explicit

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

Read More

Who uses P2786 and P1144 for trivial relocation?

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

Read More

Tangent circles of integer radius

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

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

Read More

Types that falsely advertise P2786 trivial relocatability

My previous blog post — “Types that falsely advertise trivial copyability” (2024-05-15) — refers to my as-yet-pretty-vague proposal P3279 “What ‘trivially fooable’ should mean”, where I basically propose that is_trivially_constructible<T, U> should be true if and only if T(declval<U>()) selects a constructor or conversion operator which is “known to be equivalent in its observable effects to a simple copy of the complete object representation.” This is intended to be similar to the existing wording for defaulted special members, e.g.

Read More

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 esolangs.org, the wiki for esoteric programming languages.

Read More