Home
Barry's C++ Blog
Cancel

On the Ignorability of Attributes

I was reading through the latest mailing, and a sentence caught my eye in P3661 (“Attributes, annotations, labels”), emphasis mine: Attributes turned out to be unsuitable for the role of “small features”, “small modifications to bigger features” or annotations from other languages. The need f...

Polymorphic, Defaulted Equality

I recently ran into an interesting bug that I thought was worth sharing. The Setup We have an abstract base class, with polymorphic equality: struct Base { virtual ~Base() = default; virtual auto operator==(Base const&) const -> bool = 0; }; And then we have a bunch of derived...

Implementing Trivial Relocation in Library

One of the reasons that I’m excited for Reflection in C++ is that it can permit you to implement, as a library, many things that previously required language features. In this post, I’m going to walk through implementing P2786R8 (“Trivial Relocatability For C++26”). Or, at least, just the tri...

Code Generation in Rust vs C++26

One of the things I like to do is compare how different languages solve the same problem — especially when they end up having very different approaches. It’s always educational. In this case, a bunch of us have been working hard on trying to get reflection — a really transformative language featu...

What's so hard about class types as non-type template parameters?

Setting the Stage Previously, I tried to answer the question: what’s so hard about constexpr allocation?. Today, we continue what will become a series of posts about attempting to explain the issues behind a bunch of hard problems we’re trying to solve. The next problem: class types as non-type ...

What's so hard about constexpr allocation?

Setting the Stage Before C++20, we couldn’t have any allocation during constant evaluation at all. Any attempt to do so would fail the evaluation — it would no longer be constant. In C++20, as a result of P0784R7, that changed. Finally we could do allocation during constant evaluation. However,...

Are we missing a Ranges customization point?

Let’s say we’re writing one container that we’re implementing in terms of another container. If we want to make my container a range based entirely on that other container, that’s easy: template <typename T> class StableVector { std::vector<T*> impl; public: auto begin() con...

What's the right hash table API?

The Associative Container API When it comes to a hash table, there are basically only two interesting operations from an API perspective: lookup and insertion 1. The standard library containers are all very consistent in how these operations are provided, across all the associative containers (m...

Mutating through a filter

Introduction Nico Josuttis gave a talk recently that included an example like this: std::vector<int> coll{1, 4, 7, 10}; auto isEven = [](int i) { return i % 2 == 0; }; // increment even elements: for (int& i : coll | std::views::filter(isEven)) { ++i; // UB: but works } I want...

Prefer views::meow

With the adoption of Ranges in C++20 (and with a lot of new additions in C++23), we have a lot of new, composable, range-based algorithms at our disposal. There are, however, several ways to spell the usage of such algorithms: std::vector<int> v = {1, 2, 3}; auto square = [](int i){ return...