ES.107 (and others) never mentions `std::ssize()`
@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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di isocpp/CppCoreGuidelines
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 75/100
isocpp/CppCoreGuidelines#2338 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
isocpp/CppCoreGuidelines#2205 · 8 commenti ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 64/100
isocpp/CppCoreGuidelines#1649 · 3 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
isocpp/CppCoreGuidelines#2336 · 4 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
isocpp/CppCoreGuidelines#2335 · 2 commenti ·