10

std::span has been voted into C++20. I assumed that along with std::span, there would be a convenience alias defined like this:

template <class T, size_t Extent = dynamic_extent>
using cspan = span<const T, Extent>;

To me, this seems like a really handy alias. I'd probably use cspan more often than span! According to cppreference, cspan doesn't exist. There's one mention of cspan in this paper which seems to imply that it was in the standard at some point. I can't find any other mentions.

So what happened to cspan? Was it removed? Did it ever exist at all?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Indiana Kernick
  • 5,041
  • 2
  • 20
  • 50

1 Answers1

10

Indeed, cspan does not exist and has never existed. The only name change is that span used to be spelled array_view

The reference in P1085R2:

|  3  |  Make span operate only on const T, (rename cspan, obviously :D)  |

is a joke, as implied by the :D (note that C-SPAN is a cable network that broadcasts federal government proceedings). The actual proposal was that span<T> change to behave like today's span<T const> (and cheekily be renamed to cspan).

Just write span<T const>. It's a full 5 characters longer than cspan<T>, with the added benefit that more people will know what span is.

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Barry
  • 286,269
  • 29
  • 621
  • 977
  • **five** characters longer. " const" (six characters), versus "c" (one character) - I suspect you forgot to count the space. – Martin Bonner supports Monica Jul 02 '19 at 14:51
  • 7
    @MartinBonner I wrote five characters! Shitty edit. – Barry Jul 02 '19 at 15:16
  • 1
    I think that’s rather unfortunate. 5 characters is 6.25% of a line! Of course, I could always define it myself but I truly believe that this is something that should be part of the standard library. – Indiana Kernick Jul 02 '19 at 23:25
  • 3
    @Kerndog73 I mean, 5 is also 11.9% of 42, but that doesn't really make the number any larger. I've had a `span`-like type in my codebase for years and I've never even heard anybody even suggest that writing out `const` was too long. It's not even in a place where terseness adds much value. – Barry Jul 03 '19 at 00:34