c++ - Is the second term in Qt's foreach evaluated only once? -


if have code:

foreach (qlistwidgetitem *ii, selecteditems()) {     urls.push_back(ii->data(qt::tooltip).tostring()); } 

would selecteditems() called once?

yup. create copy of returned container, , use that. (see qt foreach keyword documentation)

related:

  • since qt foreach copies container, it's best used either qt-containers (which copy-on-write) or small stl containers.
  • boost's foreach handles better, , avoids copies unless necessary.

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -