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
/////////////////////////////////////////////////////////////////////
+namespace{
+
+std::function<bool (Index const &)> IndexNameIs(docstring const & name)
+{
+ return [name](Index const & idx){ return idx.index() == name; };
+}
+
+}
+
+
Index * IndicesList::find(docstring const & name)
{
List::iterator it =
- find_if(list.begin(), list.end(), IndexNamesEqual(name));
+ find_if(list.begin(), list.end(), IndexNameIs(name));
return it == list.end() ? nullptr : &*it;
}
Index const * IndicesList::find(docstring const & name) const
{
List::const_iterator it =
- find_if(list.begin(), list.end(), IndexNamesEqual(name));
+ find_if(list.begin(), list.end(), IndexNameIs(name));
return it == list.end() ? nullptr : &*it;
}
+namespace {
+
+std::function<bool (Index const &)> IndexShortcutIs(docstring const & sc)
+{
+ return [sc](Index const & idx){ return idx.shortcut() == sc; };
+}
+
+} // namespace
+
+
Index * IndicesList::findShortcut(docstring const & shortcut)
{
List::iterator it =
- find_if(list.begin(), list.end(), IndexHasShortcut(shortcut));
+ find_if(list.begin(), list.end(), IndexShortcutIs(shortcut));
return it == list.end() ? nullptr : &*it;
}
Index const * IndicesList::findShortcut(docstring const & shortcut) const
{
List::const_iterator it =
- find_if(list.begin(), list.end(), IndexHasShortcut(shortcut));
+ find_if(list.begin(), list.end(), IndexShortcutIs(shortcut));
return it == list.end() ? nullptr : &*it;
}
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;
bool IndicesList::remove(docstring const & s)
{
size_t const size = list.size();
- list.remove_if(IndexNamesEqual(s));
+ list.remove_if(IndexNameIs(s));
return size != list.size();
}
{
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;