isocpp / isocpp/CppCoreGuidelines

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

Open
#2,294 4 comments 0 reactions 2 assignees View on GitHub

@GabrielDosReis is already working on this.

Since Jan 15, 2026.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.