Home
Barry's C++ Blog
Cancel

For Hannah

We drove Hannah home for the first time on November 10, 2012. We drove her home for the final time on December 29, 2021. In between, we got nine years of memories, milestones, and love. When we first met Hannah, she was probably around six years old, we really don’t know. She was a puppy mill ...

T* makes for a poor optional<T&>

Whenever the idea of an optional reference comes up, inevitably somebody will bring up the point that we don’t need to support optional<T&> because we already have in the language a perfectly good optional reference: T*. And these two types are superficially quite similar, which makes ...

Conditional Members

I’d previously written a post about if constexpr (and how it’s not broken). I argued in that post how, broadly speaking, C++20 gives you the tools to solve the problems you want, even if they work a bit differently to D’s static if (with one notable exception, which this post greatly expands on)....

Coercing deep const-ness

In C++, template deduction doesn’t allow for any conversion. A type matches the pattern, or it’s a deduction failure. But there’s one sort-of exception to this rule, and it’s an exception that everyone has taken advantage of: template <typename T> void takes_ptr(T const*); void f(int i) {...

Counting in Iteration Models

There’s a really interesting issue pointed out in the July 2021 mailing by way of P2406R0. Basically, in C++, the iterator loop structure ordering is as follows (I wrote it with a goto to make the ordering more obvious. Note that in C++, we start with the it != end check, not the ++it operation....

Ambiguity in template parameters

C++ has had three kinds of template parameters since basically always: type template parameters (the vast majority), non-type template parameters (sometimes called value template parameters, which strikes me as a better term), and template template parameters (parameters that are themselves templ...

C++20 Range Adaptors and Range Factories

Ranges in C++20 introduces with it a bunch of range adaptors (basically, algorithms that take one or more ranges and return a new “adapted” range) and range factories (algorithms that return a range but without a range as input). All of these algorithms have several important properties, and I’ve...

Niebloids and Customization Point Objects

C++20 Ranges bring with them several new ideas by way of solving a lot of different problems. Two of the new terms in Ranges, niebloids and customization point objects (or CPOs), are very frequently confused and used interchangeably. This confusion is pretty understandable (the two are pretty si...

Why tag_invoke is not the solution I want

C++ is a language that lauds itself on the ability to write good, efficient generic code. So it’s a little strange that here we are in C++20 and yet have surprisingly little language support for proper customization. It’s worth elaborating a bit on what I mean by “proper customization.” There ar...

Implementing a better views::split

One of the new additions to C++20 courtesy of Ranges is views::split . There are two kinds of split supported: you can split by a single element or by a range of elements. This is an incredibly useful adapter since wanting to split things comes up fairly often. But there’s a big problem with the...