File: README-strict-iterators.md

package info (click to toggle)
clazy 1.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,248 kB
  • sloc: cpp: 23,552; python: 1,450; xml: 450; sh: 237; makefile: 45
file content (19 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# strict-iterators

Warns when `iterator` objects are implicitly cast to `const_iterator`.
This is mostly equivalent to passing -DQT_STRICT_ITERATORS to the compiler.
This prevents detachments but also caches subtle bugs such as:

    QHash<int, int> wrong;
    if (wrong.find(1) == wrong.cend()) {
        qDebug() << "Not found";
    } else {
        qDebug() << "Found"; // find() detached the container before cend() was called, so it prints "Found"
    }

    QHash<int, int> right;
    if (right.constFind(1) == right.cend()) {
        qDebug() << "Not found"; // This is correct now !
    } else {
        qDebug() << "Found";
    }