[all-commits] [llvm/llvm-project] 6b9b86: ADT: Fix const-correctness of iterator facade
Duncan P. N. Exon Smith via All-commits
all-commits at lists.llvm.org
Fri Nov 12 20:44:44 PST 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6b9b86db9dd974585a5c71cf2e5231d1e3385f7c
https://github.com/llvm/llvm-project/commit/6b9b86db9dd974585a5c71cf2e5231d1e3385f7c
Author: Duncan P. N. Exon Smith <dexonsmith at apple.com>
Date: 2021-11-12 (Fri, 12 Nov 2021)
Changed paths:
M llvm/include/llvm/ADT/iterator.h
M llvm/unittests/ADT/IteratorTest.cpp
Log Message:
-----------
ADT: Fix const-correctness of iterator facade
Fix the const-ness of `iterator_facade_base::operator->` and
`iterator_facade_base::operator[]`. This is a follow-up to
1b651be0465de70cfa22ce4f715d3501a4dcffc1, which fixed const-ness of
various iterator adaptors.
Iterators, like the pointers that they generalize, have two types of
`const`.
- The `const` qualifier on members indicates whether the iterator
itself can be changed. This is analagous to `int *const`.
- The `const` qualifier on return values of `operator*()`,
`operator[]()`, and `operator->()` controls whether the the
pointed-to value can be changed. This is analogous to `const int*`.
If an iterator facade returns a handle to its own state, then T (and
PointerT and ReferenceT) should usually be const-qualified. Otherwise,
if clients are expected to modify the state itself, the field can be
declared mutable or a const_cast can be used.
More information about the All-commits
mailing list