Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ES.107 (and others) never mentions `std::ssize()`

Aperta
#2,294 4 commenti 0 reazioni 2 assegnatari Vedi su GitHub

@GabrielDosReis ci sta già lavorando.

Dal 15/1/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

At the time of writing nowhere within the Guidelines is there a single mention of the std::ssize() function added in C++20.
I might be mistaken but my understanding is that this addition to the standard library solves many of the issues with the standard containers using unsigned subscripts, or specifically the unsigned return type of the .size() method.

I have mentioned the rule ES.107 in the title as I would see the example code there a perfect place to use std::ssize().
The Enforcement section states that enforcement of ES.107 is tricky and gives the example of comparison of gsl::index with the results of .size() and sizeof. While not much can be done about sizeof the comparison issues of gsl::index with .size() are entirely (?) removed by the use of std::ssize().
Maybe sizeof is waiting for a mechanism analogous to std::ssize() 😉?

The reason I am raising this question is that I have been suggesting the use of std::ssize() in my code reviews for a while but I could not support this with anything in the Guidelines. It was relatively easy to justify, though, as it was mainly protecting against the type of issues that can arise with
my_container.size() - 1
as opposed to
std::ssize(my_container) - 1.

I believe that multiple places within the Guidelines could employ std::ssize() - many (but not all) of those that currently use .size().
Possibly even a dedicated rule for accessing sizes of standard containers with std::ssize(), if C++20 is available, could be added?

Lingua principale
CSS
Stelle
45.3k
Fork
5.6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di isocpp/CppCoreGuidelines

Tutte le issue di isocpp/CppCoreGuidelines

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.