Le 27/06/2016 23:15, Richard Heck a écrit :
On 06/27/2016 04:14 PM, Georg Baum wrote:
You mean std::bind, or did I miss any remaining boost::bind?

I just removed some leftover boost::function (not boost::bind).

For me personally the patch is too big to proof-read it. I'd prefer to
change simple things like

-       BufferStorage::iterator it = bstore.begin();
-       BufferStorage::iterator end = bstore.end();
-       for (; it != end; ++it) {
-               Buffer * buf = *it;
+       for(Buffer * buf : bstore)

which are not related to removal of std::bind first.

Yes, that's a good idea.


I have split the patch in two for you, and already committed the part
that does not introduce lambda expressions. Attached is the remainder of
the patch that replaces all remaining std::bind with lambda expressions.



Apart from that I am not too familiar with lambdas yet, so for me personally
the new code is more difficult to read than the old one ATM, and I am
probably not the only one. Your explanation to Richard is nice, but it will
soon be buried in email archives, and people reading LyX sources do not see
it.

I am not opposed to using lambdas (I hope I can learn soemthing from you
here), but I believe that our developer documentation should contain a short
motivation why they are used in LyX (you basically explained already to
Richard how they make code more readable), and a pointer to a more detailed
introduction to lambdas. Then it should also be possible for novices or old-
timers like me to understand the new hot stuff.

It wouldn't hurt to put some comments in the code, too.


I am happy to explain my code to anybody who asks. However, I am not
going to introduce a motivation for lambda expressions in the developer
manual nor add links to introductions. The old code was already using
anonymous functions; that lambda expressions is better for anonymous
functions is obvious to anybody familiar with lambda expressions; and
the documentation is not meant to be a tutorial for ISO C++.

Neither am I going to add comments to the code affected by the patch,
because nobody felt like requiring such comments for the old code.
Whereas the std::bind version can be hard to read for anybody, the new
code is self-explanatory for anybody familiar with lambda expressions,
and comments are again not meant to explain the language.

If other developers are not familiar with lambda expressions yet, then
it is appropriate to wait before committing. Given that I do not know
the source of my issue with gcc 4.6, it is appropriate to wait that
support for gcc 4.6 is dropped (probably about a year from now).

But if anybody needs to use std::bind in the future, please consider the
small investment of learning the simpler lambda expressions and use them
instead. By showing you examples of correspondence between the old codes
and the new, I hope that the attached patch will make it easier for you.

Thank you for your feedback.


Guillaume
>From bd2634b6ae1f92939d8daa65468a8479e4d02385 Mon Sep 17 00:00:00 2001
From: Guillaume Munch <g...@lyx.org>
Date: Wed, 29 Jun 2016 11:40:28 +0100
Subject: [PATCH] Remove support/functional.h and support/bind.h
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Replace std::bind() with lambdas. This provides a much more readable code.

> It would help me if you could explain this new syntax. [...]
>
>> -        theApp()->registerSocketCallback(fd,
>> -            bind(&LyXComm::read_ready, this));
>> +        theApp()->registerSocketCallback(fd, [this]() { read_ready(); });
>

In C++11, the syntax [X](Y){Z} is called a “lambda expression” and
denotes an anonymous function.

The (Y) is the list of arguments, with which you are already familiar in
function declarations, e.g. (std::string const & str). The {Z} is what
you would write in the body of such function (including the return
statement). It goes without saying that in the end, this is much
more readable and expressive than creating anonymous functions with
std::bind.

The power of the lambda expressions comes from the [X] parameter. Inside
Z, you can refer and access to any variable that you can already access
and refer to in the scope in which you write the lambda expression. For
instance, I wrote above "read_ready();" because I am essentially in the
scope of a member function of LyXComm, and therefore I can refer to (and
omit) "this->".

Now, the expression {Z} can be evaluated much later, and therefore all
the local variables it refers to may already have been destroyed.
Therefore we need the parameter [X] to indicate how the free variables
appearing in {Z} but not in (Y) are stored when creating the anonymous
function ("captured", in C++-speak). They are either stored by copying
or stored by reference. [X] is a list of variables possibly prefixed by
&, denoting a reference. For instance [x,&y,z] means that x and z are
copied and stored with the anonymous function on creation, whereas y is
stored as a reference to the original object.

In the example above, I refer (implicitly) to "this" and therefore I
must indicate that this (the pointer) is to be copied.

There are two shorthand syntaxes for [X]: [=,...] and [&,...]. =
indicates that all remaining free variables must be copied. & indicates
that all remaining variables must be stored by reference. (In both cases
the this pointer will be copied, not stored by reference.)

>>
>> +	auto compile = [=](std::string const & s) {
>> +		return clone->doExport(s, true);
>> +	};
>> +	return runAndDestroy(compile, orig, clone, format);

In the above example, the function "compile" calls clone->doExport where
"clone" is a copy of to the original pointer "clone", and where the
first argument is passed to it later by runAndDestroy.

The "auto" keyword asks to the compiler to deduce the type of the
function automatically, because the type of "compile" is too complicated
to write down. Note that it is still type-checked at compile-type (in
this case, the type is used to create an instance of the runAndDestroy
function template, and if compile was not an appropriate function, then
an error would occur at template instantiation. But one could also have
made the type explicit as std::function<Buffer::ExportStatus(std::string
const &)>).
---
 src/Buffer.cpp                     |   8 +--
 src/Server.cpp                     |   5 +-
 src/ServerSocket.cpp               |  13 ++---
 src/frontends/qt4/GuiAlert.cpp     |  54 ++++++++-----------
 src/frontends/qt4/GuiView.cpp      |  34 +++++++-----
 src/frontends/qt4/GuiWorkArea.cpp  |   8 ++-
 src/frontends/qt4/InGuiThread.h    | 108 +++++++++----------------------------
 src/graphics/GraphicsCacheItem.cpp |   5 +-
 src/graphics/GraphicsConverter.cpp |   3 +-
 src/graphics/GraphicsLoader.cpp    |   6 +--
 src/graphics/PreviewImage.cpp      |   4 +-
 src/graphics/PreviewLoader.cpp     |   5 +-
 src/insets/InsetExternal.cpp       |   3 +-
 src/insets/InsetInclude.cpp        |   6 +--
 src/insets/InsetText.cpp           |   4 +-
 src/insets/RenderGraphic.cpp       |   6 +--
 src/insets/RenderPreview.cpp       |   8 +--
 src/support/FileMonitor.cpp        |   3 +-
 src/support/ForkedCalls.cpp        |  11 ++--
 src/support/Makefile.am            |   2 -
 src/support/bind.h                 |  26 ---------
 src/support/functional.h           |  23 --------
 22 files changed, 103 insertions(+), 242 deletions(-)
 delete mode 100644 src/support/bind.h
 delete mode 100644 src/support/functional.h

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 08f3148..997cd6b 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -106,8 +106,6 @@
 #include "support/textutils.h"
 #include "support/types.h"
 
-#include "support/bind.h"
-
 #include <algorithm>
 #include <fstream>
 #include <iomanip>
@@ -2829,10 +2827,8 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
 {
 	LASSERT(from, return);
 	LASSERT(to, return);
-
-	for_each(par_iterator_begin(),
-		 par_iterator_end(),
-		 bind(&Paragraph::changeLanguage, _1, params(), from, to));
+	for_each(par_iterator_begin(), par_iterator_end(),
+	         [=](Paragraph & p){ p.changeLanguage(params(), from, to); });
 }
 
 
diff --git a/src/Server.cpp b/src/Server.cpp
index b89e834..5c81f85 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -56,8 +56,6 @@
 #include "support/lstrings.h"
 #include "support/os.h"
 
-#include "support/bind.h"
-
 #include <iostream>
 
 #ifdef _WIN32
@@ -859,8 +857,7 @@ int LyXComm::startPipe(string const & file, bool write)
 	}
 
 	if (!write) {
-		theApp()->registerSocketCallback(fd,
-			bind(&LyXComm::read_ready, this));
+		theApp()->registerSocketCallback(fd, [this]() { read_ready(); });
 	}
 
 	return fd;
diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp
index ece3549..4baef01 100644
--- a/src/ServerSocket.cpp
+++ b/src/ServerSocket.cpp
@@ -63,10 +63,7 @@ ServerSocket::ServerSocket(FileName const & addr)
 	// Needed by lyxclient
 	setEnv("LYXSOCKET", address_.absFileName());
 
-	theApp()->registerSocketCallback(
-		fd_,
-		bind(&ServerSocket::serverCallback, this)
-		);
+	theApp()->registerSocketCallback(fd_, [this]() { serverCallback(); });
 
 	LYXERR(Debug::LYXSERVER, "lyx: New server socket "
 				 << fd_ << ' ' << address_.absFileName());
@@ -113,11 +110,9 @@ void ServerSocket::serverCallback()
 
 	// Register the new client.
 	clients[client_fd] = make_shared<LyXDataSocket>(client_fd);
-	theApp()->registerSocketCallback(
-		client_fd,
-		bind(&ServerSocket::dataCallback,
-			    this, client_fd)
-		);
+	theApp()->registerSocketCallback(client_fd, [=]() {
+			dataCallback(client_fd);
+		});
 }
 
 
diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp
index 4c9b162..e268b93 100644
--- a/src/frontends/qt4/GuiAlert.cpp
+++ b/src/frontends/qt4/GuiAlert.cpp
@@ -50,6 +50,21 @@ namespace lyx {
 namespace frontend {
 
 
+namespace {
+
+// call() is just call_in_gui_thread()
+template<typename F>
+typename std::result_of<F()>::type call(F f) {
+#if EXPORT_in_THREAD
+	return call_in_gui_thread(f);
+#else
+	return f();
+#endif
+}
+
+} // anon namespace
+
+
 void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode)
 {
 	int argc = 1;
@@ -136,13 +151,10 @@ int prompt(docstring const & title0, docstring const & question,
 		  docstring const & b1, docstring const & b2,
 		  docstring const & b3, docstring const & b4)
 {
-#ifdef EXPORT_in_THREAD
-	return InGuiThread<int>().call(&doPrompt,
-#else
-	return doPrompt(
-#endif
-				title0, question, default_button,
-				cancel_button, b1, b2, b3, b4);
+	return call([&, default_button, cancel_button] () {
+			return doPrompt(title0, question, default_button,
+			                cancel_button, b1, b2, b3, b4);
+		});
 }
 
 void doWarning(docstring const & title0, docstring const & message,
@@ -190,12 +202,7 @@ void doWarning(docstring const & title0, docstring const & message,
 void warning(docstring const & title0, docstring const & message,
 	     bool const & askshowagain)
 {
-#ifdef EXPORT_in_THREAD	
-	InGuiThread<void>().call(&doWarning,
-#else
-	doWarning(
-#endif
-				title0, message, askshowagain);
+	call([&] () { doWarning(title0, message, askshowagain); });
 }
 
 void doError(docstring const & title0, docstring const & message, bool backtrace)
@@ -240,12 +247,7 @@ void doError(docstring const & title0, docstring const & message, bool backtrace
 
 void error(docstring const & title0, docstring const & message, bool backtrace)
 {
-#ifdef EXPORT_in_THREAD
-	InGuiThread<void>().call(&doError, 
-#else
-	doError(
-#endif
-				title0, message, backtrace);
+	call([&, backtrace] () { doError(title0, message, backtrace); });
 }
 
 void doInformation(docstring const & title0, docstring const & message)
@@ -285,12 +287,7 @@ void doInformation(docstring const & title0, docstring const & message)
 
 void information(docstring const & title0, docstring const & message)
 {
-#ifdef EXPORT_in_THREAD
-	InGuiThread<void>().call(&doInformation,
-#else
-	doInformation(
-#endif
-				title0, message);
+	call ([&] () { doInformation(title0, message); });
 }
 
 bool doAskForText(docstring & response, docstring const & msg,
@@ -335,12 +332,7 @@ bool doAskForText(docstring & response, docstring const & msg,
 bool askForText(docstring & response, docstring const & msg,
 	docstring const & dflt)
 {
-#ifdef EXPORT_in_THREAD
-	return InGuiThread<bool>().call(&doAskForText,
-#else
-	return doAskForText(
-#endif
-				response, msg, dflt);
+	return call([&] () { return doAskForText(response, msg, dflt); });
 }
 
 } // namespace Alert
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 429def5..bcabc1a 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -125,8 +125,6 @@
 #define EXPORT_in_THREAD 1
 
 
-#include "support/bind.h"
-
 #include <sstream>
 
 #ifdef HAVE_SYS_TIME_H
@@ -531,7 +529,7 @@ GuiView::GuiView(int id)
 
 	// Start autosave timer
 	if (lyxrc.autosave) {
-		d.autosave_timeout_.timeout.connect(bind(&GuiView::autoSave, this));
+		d.autosave_timeout_.timeout.connect([this]() { autoSave(); });
 		d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
 		d.autosave_timeout_.start();
 	}
@@ -3383,24 +3381,36 @@ Buffer::ExportStatus GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffe
 }
 
 
-Buffer::ExportStatus GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
+Buffer::ExportStatus
+GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, Buffer * clone,
+                                           string const & format)
 {
-	Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
-	return runAndDestroy(lyx::bind(mem_func, clone, _1, true), orig, clone, format);
+	auto compile = [=](std::string const & s) {
+		return clone->doExport(s, true);
+	};
+	return runAndDestroy(compile, orig, clone, format);
 }
 
 
-Buffer::ExportStatus GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
+Buffer::ExportStatus
+GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, Buffer * clone,
+                                          string const & format)
 {
-	Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
-	return runAndDestroy(lyx::bind(mem_func, clone, _1, false), orig, clone, format);
+	auto exporte = [=](std::string const & s) {
+		return clone->doExport(s, false);
+	};
+	return runAndDestroy(exporte, orig, clone, format);
 }
 
 
-Buffer::ExportStatus GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
+Buffer::ExportStatus
+GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer * clone,
+                                           string const & format)
 {
-	Buffer::ExportStatus (Buffer::* mem_func)(std::string const &) const = &Buffer::preview;
-	return runAndDestroy(lyx::bind(mem_func, clone, _1), orig, clone, format);
+	auto preview = [=](std::string const & s) {
+		return clone->preview(s);
+	};
+	return runAndDestroy(preview, orig, clone, format);
 }
 
 
diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp
index dad7de4..27de7ea 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -78,8 +78,6 @@
 #include <QToolTip>
 #include <QMenuBar>
 
-#include "support/bind.h"
-
 #include <cmath>
 
 int const TabIndicatorWidth = 3;
@@ -319,9 +317,9 @@ void GuiWorkArea::init()
 
 	d->setCursorShape(Qt::IBeamCursor);
 
-	d->synthetic_mouse_event_.timeout.timeout.connect(
-		bind(&GuiWorkArea::generateSyntheticMouseEvent,
-					this));
+	d->synthetic_mouse_event_.timeout.timeout.connect([this]() {
+			generateSyntheticMouseEvent();
+		});
 
 	// Initialize the vertical Scroll Bar
 	QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
diff --git a/src/frontends/qt4/InGuiThread.h b/src/frontends/qt4/InGuiThread.h
index 86c4afe..71595f8 100644
--- a/src/frontends/qt4/InGuiThread.h
+++ b/src/frontends/qt4/InGuiThread.h
@@ -16,13 +16,22 @@
 #include <QObject>
 #include <QWaitCondition>
 
-#include "support/bind.h"
-#include "support/functional.h"
+#include <functional>
 
 namespace lyx {
 namespace frontend {
 
 
+// calls a function f of type R() in the GUI thread, and returns the result of
+// type R.
+template<typename F>
+typename std::result_of<F()>::type call_in_gui_thread(F f);
+
+
+//
+// Template implementation
+//
+
 class IntoGuiThreadMover : public QObject
 {
 	Q_OBJECT
@@ -51,10 +60,9 @@ template<class R>
 class InGuiThread : private IntoGuiThreadMover
 {
 public:
-
 	// please coverity by explicitly initalizing this variable.
 	InGuiThread() : return_value_(R()) {}
-
+	///
 	template<class F>
 	R call(F f)
 	{
@@ -63,51 +71,15 @@ public:
 		return return_value_;
 	}
 
-	template<class F, class P1>
-	R call(F f, P1& p1)
-	{
-		return call(lyx::bind(f, lyx::ref(p1)));
-	}
-
-	template<class F, class P1, class P2>
-	R call(F f, P1& p1, P2& p2)
-	{
-		return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2)));
-	}
-
-	template<class F, class P1, class P2, class P3>
-	R call(F f, P1& p1, P2& p2, P3& p3)
-	{
-		return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3)));
-	}
-
-	template<class F, class P1, class P2, class P3, class P4>
-	R call(F f, P1& p1, P2& p2, P3& p3, P4& p4)
-	{
-		return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4)));
-	}
-
-	/*
-	  ...
-	*/
-
-	template<class F, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
-	R call(F f, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8)
-	{
-		return call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4), 
-			lyx::ref(p5), lyx::ref(p6), lyx::ref(p7), lyx::ref(p8)));
-	}
-
 private:
-
 	void synchronousFunctionCall()
 	{
 		return_value_ = func_();
 	}
-
-private:
+	///
 	R return_value_;
-	function<R()> func_;
+	///
+	std::function<R()> func_;
 };
 
 
@@ -116,9 +88,8 @@ template<>
 class InGuiThread<void> : private IntoGuiThreadMover
 {
 public:
-
 	InGuiThread() {}
-
+	///
 	template<class F>
 	void call(F f)
 	{
@@ -126,53 +97,22 @@ public:
 		callInGuiThread();
 	}
 
-	template<class F, class P1>
-	void call(F f, P1& p1)
-	{
-		call(lyx::bind(f, lyx::ref(p1)));
-	}
-
-	template<class F, class P1, class P2>
-	void call(F f, P1& p1, P2& p2)
-	{
-		call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2)));
-	}
-
-	template<class F, class P1, class P2, class P3>
-	void call(F f, P1& p1, P2& p2, P3& p3)
-	{
-		call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3)));
-	}
-
-	template<class F, class P1, class P2, class P3, class P4>
-	void call(F f, P1& p1, P2& p2, P3& p3, P4& p4)
-	{
-		call(lyx::bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4)));
-	}
-
-	/*
-	  ...
-	*/
-
-	template<class F, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
-	void call(F f, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8)
-	{
-		call(bind(f, lyx::ref(p1), lyx::ref(p2), lyx::ref(p3), lyx::ref(p4), lyx::ref(p5),
-			lyx::ref(p6), lyx::ref(p7), lyx::ref(p8)));
-	}
-
 private:
-
 	void synchronousFunctionCall()
 	{
 		func_();
 	}
-
-private:
-	function<void()> func_;
+	///
+	std::function<void()> func_;
 };
 
 
+template<typename F>
+typename std::result_of<F()>::type call_in_gui_thread(F f) {
+	return InGuiThread<typename std::result_of<F()>::type>().call(f);
+}
+
+
 } // namespace frontend
 } // namespace lyx
 
diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp
index ea59173..2709c45 100644
--- a/src/graphics/GraphicsCacheItem.cpp
+++ b/src/graphics/GraphicsCacheItem.cpp
@@ -28,7 +28,6 @@
 #include "support/lassert.h"
 #include "support/unique_ptr.h"
 
-#include "support/bind.h"
 #include "support/TempFile.h"
 
 using namespace std;
@@ -211,7 +210,7 @@ CacheItem::Impl::Impl(FileName const & file)
 	  remove_loaded_file_(false),
 	  status_(WaitingToLoad)
 {
-	monitor_.connect(bind(&Impl::startLoading, this));
+	monitor_.connect([this]() { startLoading(); });
 }
 
 
@@ -440,7 +439,7 @@ void CacheItem::Impl::convertToDisplayFormat()
 	// on completion of the conversion process.
 	converter_ = make_unique<Converter>(filename, to_file_base.absFileName(),
 	                                    from, to_);
-	converter_->connect(bind(&Impl::imageConverted, this, _1));
+	converter_->connect([this](bool b) { imageConverted(b); });
 	converter_->startConversion();
 }
 
diff --git a/src/graphics/GraphicsConverter.cpp b/src/graphics/GraphicsConverter.cpp
index ebb074c..511bf73 100644
--- a/src/graphics/GraphicsConverter.cpp
+++ b/src/graphics/GraphicsConverter.cpp
@@ -24,7 +24,6 @@
 #include "support/lstrings.h"
 #include "support/os.h"
 
-#include "support/bind.h"
 #include "support/TempFile.h"
 
 #include <sstream>
@@ -181,7 +180,7 @@ void Converter::Impl::startConversion()
 
 	ForkedCall::SignalTypePtr ptr =
 		ForkedCallQueue::add(script_command_);
-	ptr->connect(bind(&Impl::converted, this, _1, _2));
+	ptr->connect([this](pid_t p, int retval) { converted(p, retval); });
 }
 
 
diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp
index 1fa5c65..8aeb972 100644
--- a/src/graphics/GraphicsLoader.cpp
+++ b/src/graphics/GraphicsLoader.cpp
@@ -20,8 +20,6 @@
 #include "support/debug.h"
 #include "support/Timeout.h"
 
-#include "support/bind.h"
-
 #include <queue>
 #include <memory>
 #include <set>
@@ -108,7 +106,7 @@ void LoaderQueue::loadNext()
 LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
 			     running_(false)
 {
-	timer.timeout.connect(bind(&LoaderQueue::loadNext, this));
+	timer.timeout.connect([this]() { loadNext(); });
 }
 
 
@@ -414,7 +412,7 @@ void Loader::Impl::resetFile(FileName const & file)
 	if (continue_monitoring && !cached_item_->monitoring())
 		cached_item_->startMonitoring();
 
-	sc_ = cached_item_->connect(bind(&Impl::statusChanged, this));
+	sc_ = cached_item_->connect([this]() { statusChanged(); });
 }
 
 
diff --git a/src/graphics/PreviewImage.cpp b/src/graphics/PreviewImage.cpp
index 80e8e20..ad09f72 100644
--- a/src/graphics/PreviewImage.cpp
+++ b/src/graphics/PreviewImage.cpp
@@ -20,8 +20,6 @@
 
 #include "support/FileName.h"
 
-#include "support/bind.h"
-
 using namespace std;
 using namespace lyx::support;
 
@@ -107,7 +105,7 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
 	  snippet_(s), ascent_frac_(af)
 {
 	iloader_.setDisplayPixelRatio(l.displayPixelRatio());
-	iloader_.connect(bind(&Impl::statusChanged, this));
+	iloader_.connect([this]() { statusChanged(); });
 }
 
 
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index bc174da..600a3fe 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -37,7 +37,6 @@
 #include "support/ForkedCalls.h"
 #include "support/lstrings.h"
 
-#include "support/bind.h"
 #include "support/TempFile.h"
 
 #include <fstream>
@@ -741,7 +740,9 @@ void PreviewLoader::Impl::startLoading(bool wait)
 	// Initiate the conversion from LaTeX to bitmap images files.
 	ForkedCall::SignalTypePtr
 		convert_ptr(new ForkedCall::SignalType);
-	convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));
+	convert_ptr->connect([this](pid_t p, int retval) {
+			finishedGenerating(p, retval);
+		});
 
 	ForkedCall call(buffer_.filePath());
 	int ret = call.startScript(command, convert_ptr);
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index 5a7a07a..b8f3f98 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -37,7 +37,6 @@
 
 #include "graphics/PreviewLoader.h"
 
-#include "support/bind.h"
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
@@ -630,7 +629,7 @@ void InsetExternal::setParams(InsetExternalParams const & p)
 	case PREVIEW_INSTANT: {
 		renderer_.reset(new RenderMonitoredPreview(this));
 		RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview();
-		preview_ptr->fileChanged(bind(&InsetExternal::fileChanged, this));
+		preview_ptr->fileChanged([this]() { fileChanged(); });
 		if (preview_ptr->monitoring())
 			preview_ptr->stopMonitoring();
 		add_preview_and_start_loading(*preview_ptr, *this, buffer());
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 1031f3a..3b9afaa 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -62,8 +62,6 @@
 #include "support/lyxalgo.h"
 #include "support/mutex.h"
 
-#include "support/bind.h"
-
 using namespace std;
 using namespace lyx::support;
 
@@ -171,7 +169,7 @@ InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
 	  preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
 	  set_label_(false), label_(0), child_buffer_(0)
 {
-	preview_->fileChanged(bind(&InsetInclude::fileChanged, this));
+	preview_->fileChanged([this]() { fileChanged(); });
 
 	if (isListings(params())) {
 		InsetListingsParams listing_params(to_utf8(p["lstparams"]));
@@ -186,7 +184,7 @@ InsetInclude::InsetInclude(InsetInclude const & other)
 	  preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
 	  set_label_(false), label_(0), child_buffer_(0)
 {
-	preview_->fileChanged(bind(&InsetInclude::fileChanged, this));
+	preview_->fileChanged([this]() { fileChanged(); });
 
 	if (other.label_)
 		label_ = new InsetLabel(*other.label_);
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 7d28020..cf31d52 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -61,7 +61,6 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-#include "support/bind.h"
 #include "support/lassert.h"
 
 #include <algorithm>
@@ -698,8 +697,7 @@ void InsetText::appendParagraphs(ParagraphList & plist)
 	mergeParagraph(buffer().params(), pl,
 		       distance(pl.begin(), ins) - 1);
 
-	for_each(pit, plist.end(),
-		 bind(&ParagraphList::push_back, ref(pl), _1));
+	for_each(pit, plist.end(), [&](Paragraph const & p) { pl.push_back(p); });
 }
 
 
diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp
index 9d9cf31..e7ebb34 100644
--- a/src/insets/RenderGraphic.cpp
+++ b/src/insets/RenderGraphic.cpp
@@ -27,8 +27,6 @@
 #include "support/filetools.h"
 #include "support/gettext.h"
 
-#include "support/bind.h"
-
 using namespace std;
 
 namespace lyx {
@@ -36,14 +34,14 @@ namespace lyx {
 
 RenderGraphic::RenderGraphic(Inset const * inset)
 {
-	loader_.connect(bind(&Inset::updateFrontend, inset));
+	loader_.connect([=]() { inset->updateFrontend(); });
 }
 
 
 RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset)
 	: RenderBase(other), loader_(other.loader_), params_(other.params_)
 {
-	loader_.connect(bind(&Inset::updateFrontend, inset));
+	loader_.connect([=]() { inset->updateFrontend(); });
 }
 
 
diff --git a/src/insets/RenderPreview.cpp b/src/insets/RenderPreview.cpp
index e985d29..49190ee 100644
--- a/src/insets/RenderPreview.cpp
+++ b/src/insets/RenderPreview.cpp
@@ -31,8 +31,6 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 
-#include "support/bind.h"
-
 using namespace std;
 using namespace lyx::support;
 
@@ -242,8 +240,10 @@ void RenderPreview::addPreview(docstring const & latex_snippet,
 	// PreviewLoader signal that'll inform us when the preview image
 	// is ready for loading.
 	if (!ploader_connection_.connected()) {
-		ploader_connection_ = ploader.connect(
-			bind(&RenderPreview::imageReady, this, _1));
+		ploader_connection_ =
+			ploader.connect([this](graphics::PreviewImage const & pimage) {
+				imageReady(pimage);
+			});
 	}
 
 	ploader.add(snippet_);
diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp
index bdd6444..0930be3 100644
--- a/src/support/FileMonitor.cpp
+++ b/src/support/FileMonitor.cpp
@@ -15,7 +15,6 @@
 #include "support/FileName.h"
 #include "support/Timeout.h"
 
-#include "support/bind.h"
 #include <boost/signals2/trackable.hpp>
 
 using namespace std;
@@ -145,7 +144,7 @@ FileMonitor::Impl::Impl(FileName const & file_with_path, int interval)
 	  timestamp_(0),
 	  checksum_(0)
 {
-	timer_.timeout.connect(bind(&Impl::monitorFile, this));
+	timer_.timeout.connect([this]() { monitorFile(); });
 }
 
 
diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp
index 4827947..a26c19d 100644
--- a/src/support/ForkedCalls.cpp
+++ b/src/support/ForkedCalls.cpp
@@ -21,9 +21,8 @@
 #include "support/os.h"
 #include "support/Timeout.h"
 
-#include "support/bind.h"
-
 #include <cerrno>
+#include <functional>
 #include <queue>
 #include <sstream>
 #include <utility>
@@ -83,7 +82,7 @@ private:
 	Murder(int secs, pid_t pid)
 		: timeout_(1000*secs, Timeout::ONETIME), pid_(pid)
 	{
-		timeout_.timeout.connect(lyx::bind(&Murder::kill, this));
+		timeout_.timeout.connect([this]() { kill(); });
 		timeout_.start();
 	}
 
@@ -560,12 +559,10 @@ typedef ListType::iterator iterator;
 /// The child processes
 static ListType forkedCalls;
 
-iterator find_pid(pid_t pid)
+iterator find_pid(pid_t p)
 {
 	return find_if(forkedCalls.begin(), forkedCalls.end(),
-			    lyx::bind(equal_to<pid_t>(),
-			    lyx::bind(&ForkedCall::pid, _1),
-			    pid));
+	               [=](ForkedProcessPtr proc) { return proc->pid() == p; });
 }
 
 
diff --git a/src/support/Makefile.am b/src/support/Makefile.am
index 08f1c71..de67803 100644
--- a/src/support/Makefile.am
+++ b/src/support/Makefile.am
@@ -34,7 +34,6 @@ liblyxsupport_a_SOURCES = \
 	FileMonitor.h \
 	FileMonitor.cpp \
 	RandomAccessList.h \
-	bind.h \
 	Changer.h \
 	ConsoleApplication.cpp \
 	ConsoleApplication.h \
@@ -59,7 +58,6 @@ liblyxsupport_a_SOURCES = \
 	filetools.h \
 	ForkedCalls.cpp \
 	ForkedCalls.h \
-	functional.h \
 	gettext.cpp \
 	gettext.h \
 	gzstream.cpp \
diff --git a/src/support/bind.h b/src/support/bind.h
deleted file mode 100644
index 5a734ff..0000000
--- a/src/support/bind.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// -*- C++ -*-
-/**
- * \file bind.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Peter Kümmel
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LYX_BIND_H
-#define LYX_BIND_H
-
-#include "support/functional.h"
-
-namespace lyx
-{
-	using std::placeholders::_1;
-	using std::placeholders::_2;
-	using std::bind;
-	using std::ref;
-}
-
-
-#endif
diff --git a/src/support/functional.h b/src/support/functional.h
deleted file mode 100644
index 6673ded..0000000
--- a/src/support/functional.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// -*- C++ -*-
-/**
- * \file functional.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Peter Kümmel
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LYX_FUNCTIONAL_H
-#define LYX_FUNCTIONAL_H
-
-#include <functional>
-
-namespace lyx
-{
-	using std::function;
-}
-
-
-#endif
-- 
2.7.4

Reply via email to