[LyX/master] Remove functors in IndicesList.cpp.
Richard Kimberly Heck
rikiheck at lyx.org
Tue May 5 14:59:03 UTC 2020
commit 59891601546bf08d3f4d4debdb40a5045aab1ab6
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Mon May 4 20:00:55 2020 -0400
Remove functors in IndicesList.cpp.
---
src/IndicesList.cpp | 63 +++++++++++++++++---------------------------------
1 files changed, 22 insertions(+), 41 deletions(-)
diff --git a/src/IndicesList.cpp b/src/IndicesList.cpp
index 5f5a1fe..644b9c8 100644
--- a/src/IndicesList.cpp
+++ b/src/IndicesList.cpp
@@ -25,42 +25,6 @@ using namespace lyx::support;
namespace lyx {
-namespace {
-
-class IndexNamesEqual : public std::unary_function<Index, bool>
-{
-public:
- IndexNamesEqual(docstring const & name)
- : name_(name)
- {}
-
- bool operator()(Index const & index) const
- {
- return index.index() == name_;
- }
-private:
- docstring name_;
-};
-
-
-class IndexHasShortcut : public std::unary_function<Index, bool>
-{
-public:
- IndexHasShortcut(docstring const & shortcut)
- : shortc_(shortcut)
- {}
-
- bool operator()(Index const & index) const
- {
- return index.shortcut() == shortc_;
- }
-private:
- docstring shortc_;
-};
-
-} // namespace
-
-
/////////////////////////////////////////////////////////////////////
//
// Index
@@ -136,6 +100,16 @@ void Index::setColor(string const & str)
/////////////////////////////////////////////////////////////////////
+namespace{
+
+std::function<bool (Index const &)> IndexNamesEqual(docstring const & name)
+{
+ return [name](Index const & idx){ return idx.index() == name; };
+}
+
+}
+
+
Index * IndicesList::find(docstring const & name)
{
List::iterator it =
@@ -152,6 +126,16 @@ Index const * IndicesList::find(docstring const & name) const
}
+namespace {
+
+std::function<bool (Index const &)> IndexHasShortcut(docstring const & sc)
+{
+ return [sc](Index const & idx){ return idx.shortcut() == sc; };
+}
+
+} // namespace
+
+
Index * IndicesList::findShortcut(docstring const & shortcut)
{
List::iterator it =
@@ -180,9 +164,7 @@ bool IndicesList::add(docstring const & n, docstring const & s)
else
name = n.substr(i, j - i);
// Is this name already in the list?
- bool const already =
- find_if(list.begin(), list.end(),
- IndexNamesEqual(name)) != list.end();
+ bool const already = find(name);
if (!already) {
added = true;
Index in;
@@ -230,8 +212,7 @@ bool IndicesList::rename(docstring const & oldname,
{
if (newname.empty())
return false;
- if (find_if(list.begin(), list.end(),
- IndexNamesEqual(newname)) != list.end())
+ if (find(newname))
// new name already taken
return false;
More information about the lyx-cvs
mailing list