]> git.lyx.org Git - features.git/commitdiff
Replace foreach with for
authorGuillaume Munch <gm@lyx.org>
Thu, 9 Jun 2016 20:54:31 +0000 (21:54 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 12 Jun 2016 18:17:33 +0000 (19:17 +0100)
C++11 allows foreach-style iterations with the following syntax:

for (auto & element : container) {
 ...
}

src/frontends/qt4/ButtonController.cpp
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiBox.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiTexinfo.cpp
src/frontends/qt4/PanelStack.cpp
src/frontends/qt4/qt_helpers.cpp
src/support/foreach.h [deleted file]
src/tex2lyx/Parser.cpp

index bccae6a706463f355706e5c3f42d4ac64c2e676e..ccac674e4aa449f8a58edf2490663a7ee117fec1 100644 (file)
@@ -15,7 +15,6 @@
 #include "qt_helpers.h"
 
 #include "support/debug.h"
-#include "support/foreach.h"
 
 #include <QCheckBox>
 #include <QPushButton>
@@ -102,7 +101,7 @@ public:
        bool checkWidgets() const
        {
                bool valid = true;
-               foreach (const CheckedLineEdit & w, checked_widgets_) 
+               for (const CheckedLineEdit & w : checked_widgets_)
                        valid &= w.check();
                return valid;
        }
@@ -252,10 +251,8 @@ void ButtonController::refreshReadOnly() const
 {
        if (d->read_only_.empty())
                return;
-
        bool const enable = !policy().isReadOnly();
-       
-       foreach (QWidget * w, d->read_only_)
+       for(QWidget * w : d->read_only_)
                setWidgetEnabled(w, enable);
 }
 
index 4d9035ef16b6f49c3402df4afaf3a9d6aaeae3e1..3fac0b792167192f9f08c02a6df37367a7079b7d 100644 (file)
@@ -64,7 +64,6 @@
 #include "support/ExceptionMessage.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
-#include "support/foreach.h"
 #include "support/ForkedCalls.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
@@ -1877,11 +1876,12 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
                QList<GuiView *> allViews = d->views_.values();
 
-               // this foreach does not modify any buffer. It just collects info on local visibility of buffers
-               // and on which buffer is active in each view.
+               // this for does not modify any buffer. It just collects info on local
+               // visibility of buffers and on which buffer is active in each view.
                Buffer * const last = theBufferList().last();
-               foreach (GuiView * view, allViews) {
-                       // all of the buffers might be locally hidden. That is, there is no active buffer.
+               for(GuiView * view : allViews) {
+                       // all of the buffers might be locally hidden. That is, there is no
+                       // active buffer.
                        if (!view || !view->currentBufferView())
                                activeBuffers[view] = 0;
                        else
@@ -1928,7 +1928,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                }
 
                // put things back to how they were (if possible).
-               foreach (GuiView * view, allViews) {
+               for (GuiView * view : allViews) {
                        Buffer * originalBuf = activeBuffers[view];
                        // there might not have been an active buffer in this view or it might have been closed by the LFUN.
                        if (theBufferList().isLoaded(originalBuf))
@@ -2811,7 +2811,7 @@ bool GuiApplication::closeAllViews()
        theSession().lastOpened().clear();
 
        QList<GuiView *> const views = d->views_.values();
-       foreach (GuiView * view, views) {
+       for (GuiView * view : views) {
                if (!view->closeScheduled())
                        return false;
        }
@@ -2827,7 +2827,7 @@ bool GuiApplication::prepareAllViewsForLogout()
                return true;
 
        QList<GuiView *> const views = d->views_.values();
-       foreach (GuiView * view, views) {
+       for (GuiView * view : views) {
                if (!view->prepareAllBuffersForLogout())
                        return false;
        }
@@ -2846,7 +2846,7 @@ GuiView & GuiApplication::view(int id) const
 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
 {
        QList<GuiView *> const views = d->views_.values();
-       foreach (GuiView * view, views)
+       for (GuiView * view : views)
                view->hideDialog(name, inset);
 }
 
index e4d425692a7e93e1ca4d5e4fc0022099decc3367..8b0f11f1d6219030bb6ececc4540e011d95d4b71 100644 (file)
@@ -26,7 +26,6 @@
 #include "insets/InsetBox.h"
 
 #include "support/gettext.h"
-#include "support/foreach.h"
 #include "support/lstrings.h"
 
 #include <QComboBox>
index 109de9351ea4a178869b43c36baf0acbdc53ccb1..2f168beee94ee22806ac9b27bfb2551c87003a35 100644 (file)
@@ -41,7 +41,6 @@
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
-#include "support/foreach.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
index 846232289c5486c47395c02fc3ed1b211a4431ee..06e0fe8048067aab3581f1f5032253b2bd991918 100644 (file)
@@ -16,7 +16,6 @@
 #include "FuncRequest.h"
 
 #include "support/filetools.h"
-#include "support/foreach.h"
 #include "support/FileName.h"
 
 #include "qt_helpers.h"
@@ -141,7 +140,7 @@ void GuiTexInfo::updateStyles(TexFileType type)
        data.sort();
 
        fileListLW->clear();
-       foreach (QString const & item, data)
+       for(QString const & item : data)
                fileListLW->addItem(item);
 
        activeStyle_ = type;
index b2024b11998a92d972b5d6bc2ac11a7586c83a24..70ab4e0776395b98f7c4b1c416e249a7e1cc7b71 100644 (file)
@@ -16,7 +16,6 @@
 #include "qt_helpers.h"
 
 #include "support/debug.h"
-#include "support/foreach.h"
 #include "support/lassert.h"
 
 #include <QAbstractButton>
@@ -244,11 +243,11 @@ void PanelStack::search()
        // If the search string is empty we enable all the items
        // otherwise we disable everything and then selectively
        // re-enable matching items
-       foreach (QTreeWidgetItem * tree_item, panel_map_) {
+       for (QTreeWidgetItem * tree_item : panel_map_) {
                setTreeItemStatus(tree_item, enable_all);
        }
 
-       foreach (QTreeWidgetItem * tree_item, panel_map_) {
+       for (QTreeWidgetItem * tree_item : panel_map_) {
                // Current widget
                QWidget * pane_widget = widget_map_[tree_item];
 
@@ -259,7 +258,7 @@ void PanelStack::search()
                if (pane_widget) {
                        // Loops on the list of children widgets (recursive)
                        QWidgetList children = pane_widget->findChildren<QWidget *>();
-                       foreach (QWidget * child_widget, children) {
+                       for (QWidget * child_widget : children) {
                                bool widget_matches = false;
 
                                // Try to cast to the most common widgets and looks in it's content
index 71498e865cac312fd9240073ad4e6e7042da7fac..5515af57c511a51b996b54d51160a934fbe58e28 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
-#include "support/foreach.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
diff --git a/src/support/foreach.h b/src/support/foreach.h
deleted file mode 100644 (file)
index a1b5b9e..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * \file foreach.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Matthias Ettrich
- *
- * Full author contact details are available in file CREDITS.
- *
- */
-
-#ifndef FOREACH_H
-#define FOREACH_H
-
-// Code stolen from Q_FOREACH, augmented to use a reference to the
-// original container instead of a copy. Copies are cheap (if not
-// mutated) for Qt's containers due to copy-on-write. The are less
-// cheap for Standard containers, that's why the modification.
-// Drawback is that we can't use temporary containers as they
-// will be destroyed before the loop is finished. So always write
-//  
-//  Container const & container = functionReturningTemporaryOrReference()
-//  foreach (ContainerItem const & item, container) {
-//   ...
-//  }
-//
-// to extend the lifetime of the reference.
-
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL)
-
-/* make use of typeof-extension */
-template <typename T>
-class ForeachContainer {
-public:
-    inline ForeachContainer(const T & t) : c(t), brk(0), i(c.begin()), e(c.end()) { }
-    const T & c;
-    int brk;
-    typename T::const_iterator i, e;
-};
-
-#define foreach(variable, container)                                  \
-for (ForeachContainer<__typeof__(container)> _container_(container);  \
-     !_container_.brk && _container_.i != _container_.e;              \
-     __extension__  ({ ++_container_.brk; ++_container_.i; }))        \
-    for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
-
-#else 
-
-struct ForeachContainerBase {};
-
-template <typename T>
-class ForeachContainer : public ForeachContainerBase {
-public:
-    inline ForeachContainer(const T& t): c(t), brk(0), i(c.begin()), e(c.end()){}
-    const T & c;
-    mutable int brk;
-    mutable typename T::const_iterator i, e;
-    inline bool condition() const { return (!brk++ && i != e); }
-};
-
-template <typename T> inline T *foreachPointer(const T &) { return 0; }
-
-template <typename T> inline ForeachContainer<T> foreachContainerNew(const T& t)
-{ return ForeachContainer<T>(t); }
-
-template <typename T>
-inline const ForeachContainer<T> *foreachContainer(const ForeachContainerBase *base, const T *)
-{ return static_cast<const ForeachContainer<T> *>(base); }
-
-#define foreach(variable, container) \
-       for (const ForeachContainerBase &_container_ = foreachContainerNew(container); \
-                        foreachContainer(&_container_, true ? 0 : foreachPointer(container))->condition();       \
-                        ++foreachContainer(&_container_, true ? 0 : foreachPointer(container))->i)               \
-                       for (variable = *foreachContainer(&_container_, true ? 0 : foreachPointer(container))->i; \
-                                        foreachContainer(&_container_, true ? 0 : foreachPointer(container))->brk;           \
-                                        --foreachContainer(&_container_, true ? 0 : foreachPointer(container))->brk)
-#endif
-
-#endif // FOREACH_H
index 895fca221e191563f4fc84c4daf183da95d4d467..41ab92063c031a50b2a496d67dd75de963f039a6 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "Encoding.h"
 #include "Parser.h"
-#include "support/foreach.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"