commit 6144bbfbf8105b899f564350ff059b113cd354e3
Author: Guillaume Munch <[email protected]>
Date: Thu Jun 9 21:54:31 2016 +0100
Replace foreach with for
C++11 allows foreach-style iterations with the following syntax:
for (auto & element : container) {
...
}
diff --git a/src/frontends/qt4/ButtonController.cpp
b/src/frontends/qt4/ButtonController.cpp
index bccae6a..ccac674 100644
--- a/src/frontends/qt4/ButtonController.cpp
+++ b/src/frontends/qt4/ButtonController.cpp
@@ -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);
}
diff --git a/src/frontends/qt4/GuiApplication.cpp
b/src/frontends/qt4/GuiApplication.cpp
index 4d9035e..3fac0b7 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -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);
}
diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp
index e4d4256..8b0f11f 100644
--- a/src/frontends/qt4/GuiBox.cpp
+++ b/src/frontends/qt4/GuiBox.cpp
@@ -26,7 +26,6 @@
#include "insets/InsetBox.h"
#include "support/gettext.h"
-#include "support/foreach.h"
#include "support/lstrings.h"
#include <QComboBox>
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index 109de93..2f168be 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -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"
diff --git a/src/frontends/qt4/GuiTexinfo.cpp b/src/frontends/qt4/GuiTexinfo.cpp
index 8462322..06e0fe8 100644
--- a/src/frontends/qt4/GuiTexinfo.cpp
+++ b/src/frontends/qt4/GuiTexinfo.cpp
@@ -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;
diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp
index b2024b1..70ab4e0 100644
--- a/src/frontends/qt4/PanelStack.cpp
+++ b/src/frontends/qt4/PanelStack.cpp
@@ -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
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 71498e8..5515af5 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -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
index a1b5b9e..0000000
--- a/src/support/foreach.h
+++ /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
diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index 895fca2..41ab920 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -12,7 +12,6 @@
#include "Encoding.h"
#include "Parser.h"
-#include "support/foreach.h"
#include "support/lstrings.h"
#include "support/textutils.h"