Implementing span's comparisons--Barry Revzin

Not so easy.

Implementing span's comparisons

by Barry Revzin

From the article:

One of the new types in C++20 is std::span<T> (with its fixed- size counterpart std::span<T, N>). This is a very useful type, since it’s a type-erased view onto a contiguous range - but unlike more typical type erasure (e.g. std::function), there’s no overhead. I’ve previous written about span here.

In the initial design, std::span<T> had comparison operators that performed a deep comparison. Those operators were subsequently removed. I think that removal was a mistake, since these operators are very useful (as in, we have a span-like type in our codebase and we use these operators), but this blog isn’t going to be about why they were removed or why they should be added back.

Instead, this blog is about how to implement span’s comparison operators, since I think that is interesting and demonstrates a bunch of C++20 features all in one go. You can jump straight to the C++20 implementation here or you can just directly add it to your code base using my span_ext repo here...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.