This patch cleans up some usage of explicit for loops and replaces
themn with for_each iteration instead.

Also I get rid of hte lyx::back_inserter_fun stuff.

I am committing this very soon.
Please comment if you have them.

BufferView_pimpl.C         |   16 ++++---
CutAndPaste.C              |    7 +--
LaTeXFeatures.C            |    1 
buffer.C                   |   22 ++--------
buffer_funcs.C             |    8 +--
bufferlist.C               |   10 +++-
cursor.C                   |   11 ++---
frontends/qt2/lyx_gui.C    |    6 --
frontends/xforms/lyx_gui.C |    6 --
support/lyxfunctional.h    |   98 ---------------------------------------------
 10 files changed, 40 insertions(+), 145 deletions(-)

Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.558
diff -u -p -w -r1.558 BufferView_pimpl.C
--- BufferView_pimpl.C	26 Oct 2004 21:16:42 -0000	1.558
+++ BufferView_pimpl.C	6 Nov 2004 14:40:39 -0000
@@ -72,6 +72,8 @@
 
 #include <boost/bind.hpp>
 
+#include <functional>
+
 using lyx::pos_type;
 
 using lyx::support::AddPath;
@@ -90,6 +92,7 @@ using std::istringstream;
 using std::make_pair;
 using std::min;
 using std::string;
+using std::mem_fun_ref;
 
 
 extern BufferList bufferlist;
@@ -823,9 +826,9 @@ void BufferView::Pimpl::trackChanges()
 	bool const tracking = buf->params().tracking_changes;
 
 	if (!tracking) {
-		ParIterator const end = buf->par_iterator_end();
-		for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
-			it->trackChanges();
+		for_each(buf->par_iterator_begin(),
+			 buf->par_iterator_end(),
+			 bind(&Paragraph::trackChanges, _1, Change::UNCHANGED));
 		buf->params().tracking_changes = true;
 
 		// we cannot allow undos beyond the freeze point
@@ -842,9 +845,10 @@ void BufferView::Pimpl::trackChanges()
 			return;
 		}
 
-		ParIterator const end = buf->par_iterator_end();
-		for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
-			it->untrackChanges();
+		for_each(buf->par_iterator_begin(),
+			 buf->par_iterator_end(),
+			 mem_fun_ref(&Paragraph::untrackChanges));
+
 		buf->params().tracking_changes = false;
 	}
 
Index: CutAndPaste.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v
retrieving revision 1.139
diff -u -p -w -r1.139 CutAndPaste.C
--- CutAndPaste.C	13 Aug 2004 12:05:26 -0000	1.139
+++ CutAndPaste.C	6 Nov 2004 14:40:39 -0000
@@ -601,14 +601,15 @@ void replaceSelectionWithString(LCursor 
 
 	// Get font setting before we cut
 	pos_type pos = cur.selEnd().pos();
-	LyXFont const font = text->getPar(cur.selBegin().par()).
-		getFontSettings(cur.buffer().params(), cur.selBegin().pos());
+	Paragraph & par = text->getPar(cur.selEnd().par());
+	LyXFont const font =
+		par.getFontSettings(cur.buffer().params(), cur.selBegin().pos());
 
 	// Insert the new string
 	string::const_iterator cit = str.begin();
 	string::const_iterator end = str.end();
 	for (; cit != end; ++cit, ++pos)
-		text->getPar(cur.selEnd().par()).insertChar(pos, (*cit), font);
+		par.insertChar(pos, (*cit), font);
 
 	// Cut the selection
 	cutSelection(cur, true, false);
Index: LaTeXFeatures.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LaTeXFeatures.C,v
retrieving revision 1.113
diff -u -p -w -r1.113 LaTeXFeatures.C
--- LaTeXFeatures.C	2 Aug 2004 13:20:03 -0000	1.113
+++ LaTeXFeatures.C	6 Nov 2004 14:40:39 -0000
@@ -160,7 +160,6 @@ string LaTeXFeatures::getLanguages() con
 	     cit != UsedLanguages_.end();
 	     ++cit)
 		languages << (*cit)->babel() << ',';
-
 	return languages.str();
 }
 
Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.590
diff -u -p -w -r1.590 buffer.C
--- buffer.C	29 Oct 2004 15:47:52 -0000	1.590
+++ buffer.C	6 Nov 2004 14:40:39 -0000
@@ -1323,9 +1323,9 @@ void Buffer::changeLanguage(Language con
 	// Take care of l10n/i18n
 	updateDocLang(to);
 
-	ParIterator end = par_iterator_end();
-	for (ParIterator it = par_iterator_begin(); it != end; ++it)
-		it->changeLanguage(params(), from, to);
+	for_each(par_iterator_begin(),
+		 par_iterator_end(),
+		 bind(&Paragraph::changeLanguage, _1, params(), from, to));
 }
 
 
@@ -1367,20 +1367,8 @@ ParIterator Buffer::getParFromID(int id)
 
 bool Buffer::hasParWithID(int id) const
 {
-	ParConstIterator it = par_iterator_begin();
-	ParConstIterator end = par_iterator_end();
-
-	if (id < 0) {
-		// John says this is called with id == -1 from undo
-		lyxerr << "hasParWithID(), id: " << id << endl;
-		return 0;
-	}
-
-	for (; it != end; ++it)
-		if (it->id() == id)
-			return true;
-
-	return false;
+	ParConstIterator it = getParFromID(id);
+	return it != par_iterator_end();
 }
 
 
Index: buffer_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.C,v
retrieving revision 1.19
diff -u -p -w -r1.19 buffer_funcs.C
--- buffer_funcs.C	26 Mar 2004 17:49:08 -0000	1.19
+++ buffer_funcs.C	6 Nov 2004 14:40:39 -0000
@@ -31,6 +31,8 @@
 #include "support/filetools.h"
 #include "support/lyxlib.h"
 
+#include <boost/bind.hpp>
+
 using lyx::support::bformat;
 using lyx::support::FileInfo;
 using lyx::support::IsFileWriteable;
@@ -211,11 +213,7 @@ void bufferErrors(Buffer const & buf, Te
 
 void bufferErrors(Buffer const & buf, ErrorList const & el)
 {
-	ErrorList::const_iterator it = el.begin();
-	ErrorList::const_iterator end = el.end();
-
-	for (; it != end; ++it)
-		buf.error(*it);
+	for_each(el.begin(), el.end(), bind(ref(buf.error), _1));
 }
 
 
Index: bufferlist.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferlist.C,v
retrieving revision 1.143
diff -u -p -w -r1.143 bufferlist.C
--- bufferlist.C	26 Oct 2004 21:16:43 -0000	1.143
+++ bufferlist.C	6 Nov 2004 14:40:39 -0000
@@ -31,6 +31,9 @@
 
 #include <boost/bind.hpp>
 
+#include <algorithm>
+#include <functional>
+
 using lyx::support::AddName;
 using lyx::support::bformat;
 using lyx::support::GetEnvPath;
@@ -49,6 +52,8 @@ using std::find_if;
 using std::for_each;
 using std::string;
 using std::vector;
+using std::back_inserter;
+using std::transform;
 
 
 BufferList::BufferList()
@@ -195,8 +200,9 @@ bool BufferList::close(Buffer * buf, boo
 vector<string> const BufferList::getFileNames() const
 {
 	vector<string> nvec;
-	std::copy(bstore.begin(), bstore.end(),
-		  lyx::back_inserter_fun(nvec, &Buffer::fileName));
+	transform(bstore.begin(), bstore.end(),
+		  back_inserter(nvec),
+		  boost::bind(&Buffer::fileName, _1));
 	return nvec;
 }
 
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.111
diff -u -p -w -r1.111 cursor.C
--- cursor.C	26 Oct 2004 21:16:43 -0000	1.111
+++ cursor.C	6 Nov 2004 14:40:40 -0000
@@ -44,6 +44,7 @@
 #include "frontends/LyXView.h"
 
 #include <boost/assert.hpp>
+#include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 
 #include <sstream>
@@ -61,8 +62,8 @@ using std::swap;
 
 namespace {
 
-	bool positionable
-		(DocIterator const & cursor, DocIterator const & anchor)
+	bool
+	positionable(DocIterator const & cursor, DocIterator const & anchor)
 	{
 		// avoid deeper nested insets when selecting
 		if (cursor.size() > anchor.size())
@@ -624,9 +625,9 @@ void LCursor::plainInsert(MathAtom const
 
 void LCursor::insert(string const & str)
 {
-	//lyxerr << "LCursor::insert str '" << str << "'" << endl;
-	for (string::const_iterator it = str.begin(); it != str.end(); ++it)
-		insert(*it);
+	for_each(str.begin(), str.end(),
+		 boost::bind(static_cast<void(LCursor::*)(char)>
+			     (&LCursor::insert), this, _1));
 }
 
 
Index: frontends/qt2/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v
retrieving revision 1.76
diff -u -p -w -r1.76 lyx_gui.C
--- frontends/qt2/lyx_gui.C	26 Oct 2004 21:16:43 -0000	1.76
+++ frontends/qt2/lyx_gui.C	6 Nov 2004 14:40:40 -0000
@@ -231,10 +231,8 @@ void start(string const & batch, vector<
 	lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
 			  os::slashify_path(os::getTmpDir() + "/lyxsocket"));
 
-	vector<string>::const_iterator cit = files.begin();
-	vector<string>::const_iterator end = files.end();
-	for (; cit != end; ++cit)
-		view.view()->loadLyXFile(*cit, true);
+	for_each(files.begin(), files.end(),
+		 bind(&BufferView::loadLyXFile, view.view(), _1, true));
 
 	// handle the batch commands the user asked for
 	if (!batch.empty()) {
Index: frontends/xforms/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/lyx_gui.C,v
retrieving revision 1.63
diff -u -p -w -r1.63 lyx_gui.C
--- frontends/xforms/lyx_gui.C	5 Oct 2004 10:11:40 -0000	1.63
+++ frontends/xforms/lyx_gui.C	6 Nov 2004 14:40:40 -0000
@@ -304,10 +304,8 @@ void start(string const & batch, vector<
 	lyxsocket = new LyXServerSocket(&view->getLyXFunc(),
 			  os::slashify_path(os::getTmpDir() + "/lyxsocket"));
 
-	vector<string>::const_iterator cit = files.begin();
-	vector<string>::const_iterator end = files.end();
-	for (; cit != end; ++cit)
-		view->view()->loadLyXFile(*cit, true);
+	for_each(files.begin(), files.end(),
+		bind(&BufferView::loadLyXFile, view->view(), _1, true));
 
 	// handle the batch commands the user asked for
 	if (!batch.empty())
Index: support/lyxfunctional.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/lyxfunctional.h,v
retrieving revision 1.17
diff -u -p -w -r1.17 lyxfunctional.h
--- support/lyxfunctional.h	23 Aug 2003 00:16:57 -0000	1.17
+++ support/lyxfunctional.h	6 Nov 2004 14:40:40 -0000
@@ -22,104 +22,6 @@
 
 namespace lyx {
 
-template <class Cont, class Type, class MemRet>
-class back_insert_fun_iterator {
-protected:
-	Cont * container;
-	MemRet(Type::*pmf)();
-public:
-	typedef Cont container_type;
-	typedef std::output_iterator_tag iterator_category;
-	typedef void value_type;
-	typedef void difference_type;
-	typedef void pointer;
-	typedef void reference;
-
-	back_insert_fun_iterator(Cont & x, MemRet(Type::*p)())
-		: container(&x), pmf(p) {}
-
-	back_insert_fun_iterator &
-	operator=(Type * val) {
-		container->push_back((val->*pmf)());
-		return *this;
-	}
-
-	back_insert_fun_iterator &
-	operator=(Type & val) {
-		container->push_back((val.*pmf)());
-		return *this;
-	}
-
-	back_insert_fun_iterator & operator*() {
-		return *this;
-	}
-	back_insert_fun_iterator & operator++() { // prefix ++
-		return *this;
-	}
-	back_insert_fun_iterator & operator++(int) { // postfix ++
-		return *this;
-	}
-};
-
-
-template <class Cont, class Type, class MemRet>
-class const_back_insert_fun_iterator {
-protected:
-	Cont * container;
-	MemRet(Type::*pmf)() const;
-public:
-	typedef Cont container_type;
-	typedef std::output_iterator_tag iterator_category;
-	typedef void value_type;
-	typedef void difference_type;
-	typedef void pointer;
-	typedef void reference;
-
-	const_back_insert_fun_iterator(Cont & x, MemRet(Type::*p)() const)
-		: container(&x), pmf(p) {}
-
-	~const_back_insert_fun_iterator() {}
-
-	const_back_insert_fun_iterator &
-	operator=(Type const * val) {
-		container->push_back((val->*pmf)());
-		return *this;
-	}
-
-	const_back_insert_fun_iterator &
-	operator=(Type const & val) {
-		container->push_back((val.*pmf)());
-		return *this;
-	}
-
-	const_back_insert_fun_iterator & operator*() {
-		return *this;
-	}
-	const_back_insert_fun_iterator & operator++() { // prefix ++
-		return *this;
-	}
-	const_back_insert_fun_iterator & operator++(int) { // postfix ++
-		return *this;
-	}
-};
-
-
-template <class Cont, class Type, class MemRet>
-back_insert_fun_iterator<Cont, Type, MemRet>
-back_inserter_fun(Cont & cont, MemRet(Type::*p)())
-{
-	return back_insert_fun_iterator<Cont, Type, MemRet>(cont, p);
-}
-
-
-template <class Cont, class Type, class MemRet>
-const_back_insert_fun_iterator<Cont, Type, MemRet>
-back_inserter_fun(Cont & cont, MemRet(Type::*p)() const)
-{
-	return const_back_insert_fun_iterator<Cont, Type, MemRet>(cont, p);
-}
-
-
 template <class R, class C, class A>
 class compare_memfun_t {
 public:
-- 
        Lgb

Reply via email to