Boost in LyX

Yuriy Skalko yuriy.skalko at gmail.com
Sat Nov 21 00:50:21 UTC 2020


> Le 20/11/2020 à 18:33, Pavel Sanda a écrit :
>> On Fri, Nov 20, 2020 at 04:14:57PM +0100, Jean-Marc Lasgouttes wrote:
>>> Le 20/11/2020 ?? 15:33, Yuriy Skalko a écrit :
>>>> I assume that it is a template-heavy thing and it can significantly
>>>> increase compilation time (also don't know about compatibility of boost
>>>> ranges with ranges-v3 library that will be standard from C++20). Is it OK
>>>> to use it? And more general question: what parts of Boost are OK for usage
>>>> in LyX?
>>>
>>> Boost is indeed a template heavy thing. I do not know (yet) about ranges-v3,
>>> but many things graduated from boost to the standard library.
>> 
>> I would say that it would be good if we could drop boost dependency altogether
>> at some day (rather than introducing new dependencies, which are not really
>> necessary like here...)
> 
> Well, now that it is in C++20, it looks much better, doesn't it ? %-]
> I really think that range-based manipulation is much better than the 
> iterator PITA.
> 
> JMarc

What about to get rid of std algorithms and use just plain range for 
loops? No lambdas, no boost::range, fast compilation and code speed :)

If Boost is only used for temporary implementation of really useful 
features from newer standards (and only for older compilers) it should 
be Ok. And this dependency will drop itself over time. It is like 
"import from future" in Python :)

Yuriy

-------------- next part --------------
From 133b6f2d9381ace1b67217f41595882e6da7d601 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Thu, 19 Nov 2020 14:03:26 +0200
Subject: [PATCH] Use range-based loops

---
 src/KeyMap.cpp                        |  6 ++--
 src/LyXAction.cpp                     |  4 +--
 src/LyXAction.h                       |  4 +--
 src/frontends/qt/GuiCommandBuffer.cpp | 31 +++++++-------------
 src/frontends/qt/qt_helpers.cpp       |  1 -
 src/insets/ExternalSupport.cpp        |  1 -
 src/insets/InsetInclude.cpp           |  1 -
 src/insets/InsetInfo.cpp              |  6 ++--
 src/insets/InsetLabel.cpp             |  1 -
 src/mathed/MathData.cpp               |  1 -
 src/output_latex.cpp                  |  1 -
 src/support/lyxalgo.h                 | 41 ---------------------------
 12 files changed, 19 insertions(+), 79 deletions(-)

diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp
index 3698ddb642..f469da5c44 100644
--- a/src/KeyMap.cpp
+++ b/src/KeyMap.cpp
@@ -531,10 +531,8 @@ KeyMap::BindingList KeyMap::listBindings(bool unbound, KeyMap::ItemType tag) con
 	BindingList list;
 	listBindings(list, KeySequence(nullptr, nullptr), tag);
 	if (unbound) {
-		LyXAction::const_iterator fit = lyxaction.func_begin();
-		LyXAction::const_iterator const fen = lyxaction.func_end();
-		for (; fit != fen; ++fit) {
-			FuncCode action = fit->second;
+		for (auto const & name_code : lyxaction) {
+			FuncCode action = name_code.second;
 			bool has_action = false;
 			BindingList::const_iterator bit = list.begin();
 			BindingList::const_iterator const ben = list.end();
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 8b13630d86..e1d78a012f 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -4536,13 +4536,13 @@ bool LyXAction::funcHasFlag(FuncCode action,
 }
 
 
-LyXAction::const_iterator LyXAction::func_begin() const
+LyXAction::const_iterator LyXAction::begin() const
 {
 	return lyx_func_map.begin();
 }
 
 
-LyXAction::const_iterator LyXAction::func_end() const
+LyXAction::const_iterator LyXAction::end() const
 {
 	return lyx_func_map.end();
 }
diff --git a/src/LyXAction.h b/src/LyXAction.h
index 30aeac03d7..000b0fb31c 100644
--- a/src/LyXAction.h
+++ b/src/LyXAction.h
@@ -94,10 +94,10 @@ public:
 	typedef FuncMap::const_iterator const_iterator;
 
 	/// return an iterator to the start of the list of LFUNs
-	const_iterator func_begin() const;
+	const_iterator begin() const;
 
 	/// return an iterator to one past the end of the list of LFUNs
-	const_iterator func_end() const;
+	const_iterator end() const;
 
 private:
 	/// noncopyable
diff --git a/src/frontends/qt/GuiCommandBuffer.cpp b/src/frontends/qt/GuiCommandBuffer.cpp
index 06ca59ca06..d6334280ff 100644
--- a/src/frontends/qt/GuiCommandBuffer.cpp
+++ b/src/frontends/qt/GuiCommandBuffer.cpp
@@ -26,7 +26,6 @@
 #include "FuncRequest.h"
 #include "Session.h"
 
-#include "support/lyxalgo.h"
 #include "support/lstrings.h"
 
 #include <QHBoxLayout>
@@ -85,8 +84,9 @@ protected:
 GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
 	: view_(view)
 {
-	transform(lyxaction.func_begin(), lyxaction.func_end(),
-		back_inserter(commands_), firster());
+	for (auto const & name_code : lyxaction) {
+		commands_.push_back(name_code.first);
+	}
 
 	QPixmap qpup = getPixmap("images/", "up", "svgz,png");
 	QPixmap qpdown = getPixmap("images/", "down", "svgz,png");
@@ -263,18 +263,6 @@ void GuiCommandBuffer::hideParent()
 }
 
 
-namespace {
-
-class prefix_p {
-public:
-	string p;
-	prefix_p(string const & s) : p(s) {}
-	bool operator()(string const & s) const { return prefixIs(s, p); }
-};
-
-} // namespace
-
-
 string const GuiCommandBuffer::historyUp()
 {
 	if (history_pos_ == history_.begin())
@@ -299,9 +287,10 @@ vector<string> const
 GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 {
 	vector<string> comp;
-
-	lyx::copy_if(commands_.begin(), commands_.end(),
-		back_inserter(comp), prefix_p(prefix));
+	for (auto const & cmd : commands_) {
+		if (prefixIs(cmd, prefix))
+			comp.push_back(cmd);
+	}
 
 	if (comp.empty()) {
 		new_prefix = prefix;
@@ -320,8 +309,10 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 		test += tmp[test.length()];
 	while (test.length() < tmp.length()) {
 		vector<string> vtmp;
-		lyx::copy_if(comp.begin(), comp.end(),
-			back_inserter(vtmp), prefix_p(test));
+		for (auto const & cmd : comp) {
+			if (prefixIs(cmd, test))
+				vtmp.push_back(cmd);
+		}
 		if (vtmp.size() != comp.size()) {
 			test.erase(test.length() - 1);
 			break;
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index dcac28f734..108d613042 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -33,7 +33,6 @@
 #include "support/gettext.h"
 #include "support/Length.h"
 #include "support/lstrings.h"
-#include "support/lyxalgo.h"
 #include "support/os.h"
 #include "support/Package.h"
 #include "support/PathChanger.h"
diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp
index 3d7936abc7..24a228cb55 100644
--- a/src/insets/ExternalSupport.cpp
+++ b/src/insets/ExternalSupport.cpp
@@ -30,7 +30,6 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/lyxalgo.h"
 #include "support/os.h"
 #include "support/Package.h"
 
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 623152863c..0de8aa3d42 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -61,7 +61,6 @@
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h" // contains
-#include "support/lyxalgo.h"
 #include "support/mutex.h"
 #include "support/ExceptionMessage.h"
 
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index 981fa536be..2c72d9044a 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -233,10 +233,8 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
 	case MENU_INFO:
 	case ICON_INFO: {
 		result.push_back(make_pair("custom", _("Custom")));
-		LyXAction::const_iterator fit = lyxaction.func_begin();
-		LyXAction::const_iterator const fen = lyxaction.func_end();
-		for (; fit != fen; ++fit) {
-			string const lfun = fit->first;
+		for (auto const & name_code : lyxaction) {
+			string const lfun = name_code.first;
 			if (!lfun.empty())
 				result.push_back(make_pair(lfun, from_ascii(lfun)));
 		}
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 427df8a767..ce4494759c 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -41,7 +41,6 @@
 #include "support/convert.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/lyxalgo.h"
 
 using namespace std;
 using namespace lyx::support;
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 53724303a9..50fc100e64 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -37,7 +37,6 @@
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
-#include "support/lyxalgo.h"
 
 #include <cstdlib>
 
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 12bbdeade7..71ebf0301f 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -35,7 +35,6 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/lstrings.h"
-#include "support/lyxalgo.h"
 #include "support/textutils.h"
 #include "support/gettext.h"
 
diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h
index 8bf8bbc541..8777a03e41 100644
--- a/src/support/lyxalgo.h
+++ b/src/support/lyxalgo.h
@@ -14,11 +14,6 @@
 #ifndef LYX_ALGO_H
 #define LYX_ALGO_H
 
-#include <utility>
-#include <iterator>
-#include <algorithm>
-
-
 namespace lyx {
 
 
@@ -48,42 +43,6 @@ bool sorted(For first, For last, Cmp cmp)
 }
 
 
-struct firster {
-	template <class P1, class P2>
-	P1 operator()(std::pair<P1, P2> const & p) {
-		return p.first;
-	}
-};
-
-
-/**
- * copy elements in the given range to the output iterator
- * if the predicate evaluates as true
- */
-template <class InputIter, class OutputIter, class Func>
-OutputIter copy_if(InputIter first, InputIter last,
-	       OutputIter result, Func func)
-{
-	for (; first != last; ++first) {
-		if (func(*first)) {
-			*result++ = *first;
-		}
-	}
-	return result;
-}
-
-
-/// Remove all duplicate entries in c.
-template<class C>
-void eliminate_duplicates(C & c)
-{
-	// It is a requirement that the container is sorted for
-	// std::unique to work properly.
-	std::sort(c.begin(), c.end());
-	c.erase(std::unique(c.begin(), c.end()), c.end());
-}
-
-
 } // namespace lyx
 
 #endif // LYX_ALGO_H
-- 
2.28.0.windows.1



More information about the lyx-devel mailing list