Angus Leeming <[EMAIL PROTECTED]> writes:

>> that is of course also my goal. and a lot of intent is hidden in bad
>> nameing. (match() anyone..., ok we are matching... but _what_. Just
>> naming the functor EqualBranchNames() would make things a lot
>> nicer.)
>
| Agree whole-hearedly.

So this is what my new version of BranchList.C looks like:

Index: BranchList.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BranchList.C,v
retrieving revision 1.10
diff -u -p -b -r1.10 BranchList.C
--- BranchList.C	14 Dec 2003 16:33:51 -0000	1.10
+++ BranchList.C	5 Jan 2004 10:32:36 -0000
@@ -12,14 +12,23 @@
 
 #include "BranchList.h"
 
-#include <boost/assert.hpp>
+using std::string;
 
-#include <functional>
+namespace {
 
+class BranchNamesEqual : public std::unary_function<Branch, bool> {
+public:
+	BranchNamesEqual(string const & name)
+		: name_(name) {}
+	bool operator()(Branch const & branch) const
+	{
+		return branch.getBranch() == name_;
+	}
+private:
+	string name_;
+};
 
-using std::string;
-using std::bind2nd;
-using std::binary_function;
+} // namespace anon
 
 
 string const & Branch::getBranch() const
@@ -61,23 +70,10 @@ void Branch::setColor(string const & c)
 }
 
 
-namespace {
-
-struct SameName {
-	SameName(string const & name) : name_(name) {}
-	bool operator()(Branch const & branch) const
-		{ return branch.getBranch() == name_; }
-private:
-	string name_;
-};
-
-}// namespace anon
-
-
 Branch * BranchList::find(std::string const & name)
 {
 	List::iterator it =
-		std::find_if(list.begin(), list.end(), SameName(name));
+		std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
 	return it == list.end() ? 0 : &*it;
 }
 
@@ -85,7 +81,7 @@ Branch * BranchList::find(std::string co
 Branch const * BranchList::find(std::string const & name) const
 {
 	List::const_iterator it =
-		std::find_if(list.begin(), list.end(), SameName(name));
+		std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
 	return it == list.end() ? 0 : &*it;
 }
 
@@ -104,13 +100,9 @@ bool BranchList::add(string const & s)
 		// Is this name already in the list?
 		List::const_iterator it = list.begin();
 		List::const_iterator end = list.end();
-		bool already = false;
-		for (; it != end; ++it) {
-			if (it->getBranch() == name) {
-				already = true;
-				break;
-			}
-		}
+		bool const already =
+			std::find_if(list.begin(), list.end(),
+				     BranchNamesEqual(name)) != end;
 		if (!already) {
 			added = true;
 			Branch br;
@@ -127,20 +119,9 @@ bool BranchList::add(string const & s)
 }
 
 
-namespace {
-
-struct match : public binary_function<Branch, string, bool> {
-	bool operator()(Branch const & br, string const & s) const {
-	return (br.getBranch() == s);
-	}
-};
-
-} // namespace anon.
-
-
 bool BranchList::remove(string const & s)
 {
 	List::size_type const size = list.size();
-	list.remove_if(bind2nd(match(), s));
+	list.remove_if(BranchNamesEqual(s));
 	return size != list.size();
 }
-- 
        Lgb

Reply via email to