mercredi 5 août 2015

QRegExp weird behaviour in for loop


QList<QRegExp> ignores;
ignores.append(QRegExp("*", Qt::CaseSensitive, QRegExp::Wildcard));
QStringList l;
l.append("sau");
l.append("bär");
for (const QString& s : l)
    //for (QList<QRegExp>::iterator i = ignores.begin(); i != ignores.end(); ++i)
    //for (QRegExp& ignore : ignores)
    for (QRegExp ignore : ignores)
        if(ignore.exactMatch(s))
            continue;

If I test this code only the third for loop matches. The former two versions do not match. I know that the working version of the rangebased for-loops makes a copy of the object, but why does a reference not match?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire