C++ (Qt)template <typename T>class QForeachContainer {public: inline QForeachContainer(const T& t) : c(t), brk(0), i(c.begin()), e(c.end()) { } // <<<<<< При создании объекта QForeachContainer контейнер копируется const T c; // <<<<<< в константный объект c int brk; typename T::const_iterator i, e;}; #define Q_FOREACH(variable, container) \for (QForeachContainer<__typeof__(container)> _container_(container); \ !_container_.brk && _container_.i != _container_.e; \ __extension__ ({ ++_container_.brk; ++_container_.i; })) \ for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
QString str1; //refers to the shared_nullQString str2; //refers to the shared_nullstr1 = "new string";str2 = str1; // str1 and str2 refer to the same datastr1 += "add new data"; // is occuring data copy for str1
C++ (Qt)size_t i, limit = myList.size();for (i = 0; i < limit; ++i) if (myList[i])..