Le 05/07/2016 à 20:39, Georg Baum a écrit :
Guillaume Munch wrote:
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.
Thanks. I am currently swamped with work, and this deserves a thorough look
so please be patient for a few days for my answer.
Hi Georg,
Here's the latest version of the patch. In this version I have decided
to follow the rule of doing capture by copy unless it is clear that the
reference will still be valid. Safety is well worth the cost. (And it
makes proof-reading simpler :)
In addition you will see that there is a "FIXME" comment for Windows and
I would gladly use your help with this one.
Thanks!
Guillaume
>From 14fa7667503cf95d1285bc474a7e877ebb3cc8d9 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 | 6 +-
src/ServerSocket.cpp | 13 ++---
src/frontends/qt4/GuiAlert.cpp | 58 ++++++++-----------
src/frontends/qt4/GuiView.cpp | 34 +++++++----
src/frontends/qt4/GuiWorkArea.cpp | 8 +--
src/frontends/qt4/InGuiThread.h | 114 ++++++++++---------------------------
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 | 6 +-
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, 114 insertions(+), 244 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 77ef949..9136842 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -107,8 +107,6 @@
#include "support/textutils.h"
#include "support/types.h"
-#include "support/bind.h"
-
#include <algorithm>
#include <fstream>
#include <iomanip>
@@ -2831,10 +2829,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..e2a3a12 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,8 @@ int LyXComm::startPipe(string const & file, bool write)
}
if (!write) {
- theApp()->registerSocketCallback(fd,
- bind(&LyXComm::read_ready, this));
+ // FIXME: on Windows the signature is read_ready(DWORD)
+ theApp()->registerSocketCallback(fd, [this]() { read_ready(); });
}
return fd;
diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp
index fd903ce..d682858 100644
--- a/src/ServerSocket.cpp
+++ b/src/ServerSocket.cpp
@@ -67,10 +67,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());
@@ -117,11 +114,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..f9ff998 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([=] () {
+ return doPrompt(title0, question, default_button,
+ cancel_button, b1, b2, b3, b4);
+ });
}
void doWarning(docstring const & title0, docstring const & message,
@@ -188,14 +200,9 @@ void doWarning(docstring const & title0, docstring const & message,
}
void warning(docstring const & title0, docstring const & message,
- bool const & askshowagain)
+ 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([=] () { 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,
@@ -333,14 +330,9 @@ bool doAskForText(docstring & response, docstring const & msg,
}
bool askForText(docstring & response, docstring const & msg,
- docstring const & dflt)
+ 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 925dfec..92bda23 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();
}
@@ -3378,24 +3376,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 69090b3..a049222 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>
#include <iostream>
@@ -320,9 +318,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..6977088 100644
--- a/src/frontends/qt4/InGuiThread.h
+++ b/src/frontends/qt4/InGuiThread.h
@@ -16,13 +16,28 @@
#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.
+//
+// Thanks to lambda expression this is all that we need, e.g.:
+// call_in_gui_thread([=](){ f(a, b, c); });
+//
+// Notice that it is better to store the captured variables by copy if it
+// cannot be guaranteed that they will still live when the function is called.
+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 +66,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 +77,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 +94,8 @@ template<>
class InGuiThread<void> : private IntoGuiThreadMover
{
public:
-
InGuiThread() {}
-
+ ///
template<class F>
void call(F f)
{
@@ -126,53 +103,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 36a6c06..f8a4284 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>
@@ -107,7 +105,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(); });
}
@@ -413,7 +411,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 e1a47e8..d932f2b 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -38,7 +38,6 @@
#include "support/ForkedCalls.h"
#include "support/lstrings.h"
-#include "support/bind.h"
#include "support/TempFile.h"
#include <atomic>
@@ -743,7 +742,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 e2ac61c..f690ca3 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -39,7 +39,6 @@
#include "graphics/PreviewLoader.h"
-#include "support/bind.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
@@ -631,7 +630,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 47c9a61..4cd07b8 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -63,8 +63,6 @@
#include "support/lyxalgo.h"
#include "support/mutex.h"
-#include "support/bind.h"
-
using namespace std;
using namespace lyx::support;
@@ -172,7 +170,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"]));
@@ -187,7 +185,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 df4f6e2..311e6d3 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -57,7 +57,6 @@
#include "frontends/alert.h"
#include "frontends/Painter.h"
-#include "support/bind.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
@@ -65,6 +64,8 @@
#include "support/lstrings.h"
#include "support/RefChanger.h"
+#include "support/lassert.h"
+
#include <algorithm>
@@ -727,8 +728,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