[Interest] Q_FOREACH creating copy , was (no subject)
Prav
pr12og2 at programist.ru
Wed Jul 1 15:58:39 CEST 2015
Forgot to answer to this:
> Qt Creator does handle foreach, forever, emit, signals, slots (and their Q_ +
> uppercase versions) specially, indeed. It treats them as keywords, as opposed
> to macros. But other than that, I don't see why your own macro wouldn't work
> in Creator.
Thiago, can you check what you can get in places marked with<<Can you get code completion here?>> inside QtCreator?
template <typename T>
class QForeachRefContainer {
QForeachRefContainer &operator=(const QForeachRefContainer &) Q_DECL_EQ_DELETE;
public:
inline QForeachRefContainer(const T& t) : c(t), i(c.begin()), e(c.end()), control(1) { }
const T &c;
typename T::const_iterator i, e;
int control;
};
#define Q_FOREACHREF(variable, container) \
for (QForeachRefContainer<QT_FOREACH_DECLTYPE(container)> _container_((container)); \
_container_.control && _container_.i != _container_.e; \
++_container_.i, _container_.control ^= 1) \
for (variable = *_container_.i; _container_.control; _container_.control = 0)
#define foreachref Q_FOREACHREF
void test1() {
QStringList container;
foreach(const auto &item, container) {
item.<<Can you get code completion here?>>
}
foreachref(const auto &item, container) {
item.<<Can you get code completion here?>>
}
}
More information about the Interest
mailing list