Home
Barry's C++ Blog
Cancel

Concept template parameters 2

A few months ago, I wrote a post with some motivating examples, and I just wanted to add some more to the list. RangeOf Sometimes, we want to write an algorithm that takes a range of some specific type. Say, we want to operate specifically over ints. We can do that: template <typename R, ty...

if constexpr isn't broken

Andrei Alexandrescu’s Meeting C++ Keynote The Next Big Thing was just posted recently on YouTube. I am a big fan of Andrei on a number of levels - he is very much my idol. This last talk that he gave was about the limitations of if constexpr as compared to “another language” and how C++ should do...

Concept template parameters

I thought I’d take a break from writing about <=> and talk instead about Concepts. One of the things you cannot do with Concepts is use them as template parameters. Which means that you cannot compose concepts in any way except strictly using && or ||. This still gets a lot of good ...

Unconditionally implementing spaceship

In my previous post, I demonstrated how to provide operator<=> for a class template conditioned on whether its underlying type provided operator<=> (i.e. Sometimes Spaceship). The key insight there was to ensure that <=> is more constrained than each of <, >, <=, and &g...

Conditionally implementing spaceship

When it comes to adopting operator<=> for library class templates, there are three choices a library can make: Just don’t adopt it (Never Spaceship) Conditionally adopt it if all of its constituent types provide it (Sometimes Spaceship) Unconditionally adopt it, if necessary assumi...

Getting in trouble with mixed comparisons

Andrzej has a great new post about the difficulty that arises when the language or the library tries to make assumptions about programmer intent. He brings up two examples of this difficulty: should CTAD wrap or copy? how should optional’s mixed comparison behave? I’ve touched on the first...

span: the best span

This post is a response to RangeOf: A better span, which has many problems worth addressing in detail. While most of this post will deal with specifically std::span<T> (which is indeed the best span), the last section will also discuss a recent addition to the standard library: std::ranges:...

Improvements to <=>

Last week, the C++ Standards Committee met in San Diego to work on C++20. One of my own main goals was to discuss two papers I wrote making improvements to a new language feature for C++20: operator <=>, also known as the three-way comparison operator but better known as the spaceship opera...

Declarations using Concepts

One of my all-time favorite C++ talks is Ben Deane’s Using Types Effectively from CppCon 2016. I like it for a lot of reasons, but for the purposes of this post - I really like the game Ben plays (starting at around the 29m mark) where he gives a function signature of a total function template - ...

Higher Order Fun

… in C++. That seems like a fundamentally wrong statement to make right? C++ has been greatly improving over the last few standards in its direct support for a more functional style of programming. But it’s still much more verbose than necessary to write a simple lambda, it’s surprisingly tricky...