Warning, file /include/QtCore/qforeach.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef QFOREACH_H
0006 #define QFOREACH_H
0007
0008 #include <QtCore/qtclasshelpermacros.h>
0009 #include <QtCore/qtconfigmacros.h>
0010 #include <QtCore/qtdeprecationmarkers.h>
0011 #include <QtCore/qttypetraits.h>
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 #if 0
0016 #pragma qt_class(QForeach)
0017 #pragma qt_sync_stop_processing
0018 #endif
0019
0020 #ifndef QT_NO_FOREACH
0021
0022 namespace QtPrivate {
0023
0024 template <typename T>
0025 class QForeachContainer {
0026 Q_DISABLE_COPY_MOVE(QForeachContainer)
0027 public:
0028 QForeachContainer(const T &t) : c(t), i(std::as_const(c).begin()), e(std::as_const(c).end()) {}
0029 QForeachContainer(T &&t) : c(std::move(t)), i(std::as_const(c).begin()), e(std::as_const(c).end()) {}
0030
0031 T c;
0032 typename T::const_iterator i, e;
0033 };
0034
0035
0036 template <typename T, typename = decltype(std::declval<T>().detach())>
0037 inline void warnIfContainerIsNotShared(int) {}
0038
0039 #if QT_DEPRECATED_SINCE(6, 0)
0040
0041 template <typename T>
0042 QT_DEPRECATED_VERSION_X_6_0("Do not use foreach/Q_FOREACH with containers which are not implicitly shared. "
0043 "Prefer using a range-based for loop with these containers: `for (const auto &it : container)`, "
0044 "keeping in mind that range-based for doesn't copy the container as Q_FOREACH does")
0045 inline void warnIfContainerIsNotShared(...) {}
0046 #endif
0047
0048 template<typename T>
0049 QForeachContainer<typename std::decay<T>::type> qMakeForeachContainer(T &&t)
0050 {
0051 warnIfContainerIsNotShared<typename std::decay<T>::type>(0);
0052 return QForeachContainer<typename std::decay<T>::type>(std::forward<T>(t));
0053 }
0054
0055 }
0056
0057
0058
0059 #define Q_FOREACH_IMPL(variable, name, container) \
0060 for (auto name = QtPrivate::qMakeForeachContainer(container); name.i != name.e; ++name.i) \
0061 if (variable = *name.i; false) {} else
0062
0063 #define Q_FOREACH_JOIN(A, B) Q_FOREACH_JOIN_IMPL(A, B)
0064 #define Q_FOREACH_JOIN_IMPL(A, B) A ## B
0065
0066 #define Q_FOREACH(variable, container) \
0067 Q_FOREACH_IMPL(variable, Q_FOREACH_JOIN(_container_, __LINE__), container)
0068 #endif
0069
0070 #define Q_FOREVER for(;;)
0071 #ifndef QT_NO_KEYWORDS
0072 # ifndef QT_NO_FOREACH
0073 # ifndef foreach
0074 # define foreach Q_FOREACH
0075 # endif
0076 # endif
0077 # ifndef forever
0078 # define forever Q_FOREVER
0079 # endif
0080 #endif
0081
0082 QT_END_NAMESPACE
0083
0084 #endif