# while (auto x=y; z)

This question has come up at least twice on the cpplang Slack now. C++ keeps adding more and more knobs to if and for and switch; why hasn’t it messed with while? Specifically, why isn’t there a “two-part while loop”?

# Homeworlds Puzzle: Burnt Umber

Here’s another Binary Homeworlds puzzle. I posted it to BoardGameGeek back in early September, but might as well record it here too.

# std::once_flag is a glass hill

Yesterday I did a followup Q&A session for my CppCon 2020 presentation “Back to Basics: Concurrency.” (These followup sessions aren’t recorded.) During the Q&A, there was some discussion of std::once_flag. Let’s repeat my table of the three C++11 synchronization primitives (which was briefly flashed as slide 34 in the recorded talk, but I was running behind at that point and didn’t stop to discuss it):

# Thoughts on OEIS A125508

Besides Scott Kim’s “Celebration of Mind” talk discussed in my previous post, I also today attended Gordon Hamilton’s talk on “Mini Mathematical Universes.” (Hamilton is also known as the designer of the board game Santorini (2016).) This was essentially an excuse to talk about a numerical process that Hamilton calls “Integral Fission.”

# Scott Kim’s rotational ambigrams for the Celebration of Mind

The “Celebration of Mind” is held annually on or around Martin Gardner’s birthday (October 21st). This year, the 10th annual CoM is being held virtually all week long, with Zoom webinars at noon, 4pm, and 8pm daily from Saturday 2020-10-17 until Friday 2020-10-23.

# Site reliability engineering at Ardeer; eyewitnesses to Hiroshima

Via Hacker News and Roger Curry’s blog, a description of Alfred Nobel’s dynamite factory in North Ayrshire. H.J.W. Dam writes in McClure’s Magazine (1897) of the many security precautions taken at “The Great Dynamite Factory at Ardeer.” First, all entrants must be stripped of all metal objects that might cause a spark.

# Conway’s Soldiers

The other day I learned about Conway’s Soldiers: Consider playing peg solitaire on an infinite grid of holes, where initially an infinite number of pegs fill the entire half-plane south of the line $$y=0$$. The goal is to advance one peg as far north as possible, by repeatedly jumping and removing pegs in the usual peg-solitaire fashion.

# A case study in implementation inheritance

The more I deal with classically polymorphic code, the more I appreciate the “modern” idioms that have grown up around it — the Non-Virtual Interface Idiom; Liskov substitutability; Scott Meyers’ dictum that classes should be either abstract or final; the rule that every hierarchy should have exactly two levels; and the rule that base classes express commonality of interface, not reuse of implementation.

Today I’d like to present a chunk of code that shows how “implementation inheritance” ended up causing trouble, and the particular patterns I applied to disentangle it. Unfortunately, the offending code is pretty messy, so I’ll use a simplified and domain-shifted example; and I’ll try to build it up in stages. …

# Left-folding and right-folding an arbitrary callable

Nerdsnipe: Given an arbitrary binary callable f(x,y), write a function left_fold such that left_fold(f)(a,b,c,...) evaluates to f(f(f(a,b),c),...). Write a function right_fold such that right_fold(f)(a,b,c,...) evaluates to f(a, f(b, f(c, ...))).

This blog post was inspired by my answer to a question on Code Review StackExchange. To utterly oversimplify the question: When is it appropriate to use classical inheritance?

# Solo-player rules for Colossal Cave: The Board Game

Back in 2013, I Kickstarted Colossal Cave: The Board Game, a board-game adaptation of Adventure. (See the Kickstarter campaign here. I’m quite proud of that campaign. You can still find copies of the game on Amazon.)

Seven years later, I’ve finally tried out a single-player variant originally inspired by BoardGameGeek poster Tracy Smith, and I’m pleased to say that it works pretty well! In this variant, you’re playing against the clock, trying to deposit as many treasures as you can before the draw pile runs out. …

# Classically polymorphic visit replaces some uses of dynamic_cast

I’ve informally described this C++ utility to several people by now; it’s time I just wrote it up in a blog post. This utility lets you “visit” a polymorphic base object as if it were a variant, by specifying the domain of possible child types at the point of the call to visit. my::visit<X,Y,Z>(b, f) returns f(static_cast<X&>(b)) if the dynamic type of b is exactly X; f(static_cast<Y&>(b)) if the dynamic type of b is exactly Y; and so on. It perfectly forwards the argument when making the call to f.

# September blog roundup

I can’t exactly call this “What I’m reading lately,” because I haven’t gotten around to fully exploring these trees. But here are two blogs I recently discovered with good stuff.

# Why do I get a linker error with static const and value_or?

In my Back to Basics talk on “Algebraic Data Types,” I cut some slides at the last minute. (I still ended up going over time a bit.) Once you’re able to download the slides from CppCon’s slides repository, you’ll see three bonus slides at the end. One was on the fact that you can (but shouldn’t!) use std::variant<T,E> as a poor man’s version of Expected<T>. The other two were on a minor pitfall that seems to bite me every time I update a piece of legacy code to use std::optional.

# C++ Pub Quiz at CppCon 2020, Game Two

Last night I emceed Game 2 of CppCon 2020’s “C++ Pub Quiz.” This time, six teams participated. Thanks to std::locale::facet, Team SFINAE, 2*Alex, auto team;, std::make_exceptional_future, and our winning team, Team SNPIOR (“Shall Not Participate In Overload Resolution”)!

# C++ Pub Quiz at CppCon 2020

CppCon 2020 is half over; this afternoon I gave my B2B talk on algebraic data types. On Friday I give my B2B talk on concurrency, and next week I’ll deliver my three-day “Classic STL” training course — for which there is still time to register! :)

Tonight I emceed the first game of the second annual CppCon “C++ Pub Quiz.” (There’s a second game happening tomorrow night.) What is C++ Pub Quiz, you ask? It’s a straightforward trivia night — five rounds, ten questions per round, write down your team’s answers on a sheet of paper and turn it in at the end of the round. High score after five rounds wins the game.

Seven teams participated in Pub Quiz. Thanks to std::my_teammates_dont_respond_exception, Team C⁠-⁠-, Team Don’t Care, The French Connection, Team Sea Slug, DROP TABLE * FROM ANSWERS, Team 0x1010, and Team IFNDR! …

It’s almost time for CppCon 2020! The conference is happening entirely online this year. I’ve been quite impressed with the amount of polish that’s gone into it. If you’re still on the fence about whether CppCon is right for you, I think 2020 would be a great year to try it out: You can “attend” from home, for a vastly reduced conference ticket price of only $300 for the whole five-day conference. (I have been informed that$50 student-price tickets, also, are still available as of this writing.)