I would suggest that your definition of "trivial" does not match your definition of the author of the code.
If size not saved, I would expect begin and end be saved, and size as the difference between the two, and this code will be embedded. Thus, we mainly talk with two (nearby) images of memory access and subtraction instead of a single memory access.
For most practical purposes, both of these are trivial, and if the author of the standard library believes that the result of this calculation should not be cached, then personally I gladly accept their opinion. But the author of this code comment might think differently.
The IIRC standard says somewhere that size "must be" O (1), not sure if it is in the text for sequences or for containers. I do not think that he does not indicate anywhere that this should be for vector . But even if we read that as an integral requirement, a fundamental QOI problem arises here - what do I do when I optimize my code for such a poor implementation through regular implementations?
If someone uses such an implementation, apparently because they want their code to run slowly. Who am I to judge otherwise ?; -)
It is also possible that the author of the code has profiled using a number of end-begin implementations and measured significant improvement by caching size. But I think it is less likely that the author is too pessimistic in the worst case scenario that their code should handle.
source share