View | Details | Raw Unified | Return to bug 243349 | Differences between
and this patch

Collapse All | Expand All

(-)src/corelib/global/qglobal.h (-5 / +15 lines)
Lines 2481-2502 typedef uint Flags; Link Here
2481
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
2481
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
2482
#endif /* Q_NO_TYPESAFE_FLAGS */
2482
#endif /* Q_NO_TYPESAFE_FLAGS */
2483
#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_RVCT)
2483
#if (defined(Q_CC_GNU) && !defined(Q_CC_RVCT))
2484
/* make use of typeof-extension */
2484
/* make use of typeof-extension */
2485
template <typename T>
2485
template <typename T>
2486
class QForeachContainer {
2486
class QForeachContainer {
2487
public:
2487
public:
2488
    inline QForeachContainer(const T& t) : c(t), brk(0), i(c.begin()), e(c.end()) { }
2488
    inline QForeachContainer(const T& t) : c(t), i(c.begin()), e(c.end()), control(1) { }
2489
    const T c;
2489
    const T c;
2490
    int brk;
2490
    int brk;
2491
    typename T::const_iterator i, e;
2491
    typename T::const_iterator i, e;
2492
    int control;
2492
};
2493
};
2494
// Explanation of the control word:
2495
//  - it's initialized to 1
2496
//  - that means both the inner and outer loops start
2497
//  - if there were no breaks, at the end of the inner loop, it's set to 0, which
2498
//    causes it to exit (the inner loop is run exactly once)
2499
//  - at the end of the outer loop, it's inverted, so it becomes 1 again, allowing
2500
//    the outer loop to continue executing
2501
//  - if there was a break inside the inner loop, it will exit with control still
2502
//    set to 1; in that case, the outer loop will invert it to 0 and will exit too
2493
#define Q_FOREACH(variable, container)                                \
2503
#define Q_FOREACH(variable, container)                                \
2494
for (QForeachContainer<__typeof__(container)> _container_(container); \
2504
for (QForeachContainer<__typeof__(container)> _container_(container); \
2495
     !_container_.brk && _container_.i != _container_.e;              \
2505
     _container_.control && _container_.i != _container_.e;         \
2496
     __extension__  ({ ++_container_.brk; ++_container_.i; }))                       \
2506
     ++_container_.i, _container_.control ^= 1)                     \
2497
    for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
2507
    for (variable = *_container_.i; _container_.control; _container_.control = 0)
2498
#else
2508
#else

Return to bug 243349