]> git.lyx.org Git - lyx.git/blobdiff - src/support/foreach.h
Fix 'Export As...' in non-English localizations
[lyx.git] / src / support / foreach.h
index 3bcb1a03c83e54af6e79e19fa210209ca0259f5c..a1b5b9e064eda435ef04382870f08491dd543b0b 100644 (file)
@@ -1,4 +1,3 @@
-
 /**
  * \file foreach.h
  * This file is part of LyX, the document processor.
@@ -8,10 +7,24 @@
  *
  * Full author contact details are available in file CREDITS.
  *
- * A collection of unicode conversion functions, using iconv.
  */
 
 #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)
 
@@ -38,7 +51,7 @@ 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()){};
+    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;