From 489dca71cd99bbc78780fa40311a2eb042c0320e Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Wed, 29 Jun 2016 10:22:13 +0100 Subject: [PATCH] Simplifications, mainly removal of boost::function and useless std::bind --- src/Buffer.cpp | 4 +-- src/Buffer.h | 2 +- src/BufferList.cpp | 51 ++++++++-------------------- src/Cursor.cpp | 7 ++-- src/LayoutFile.cpp | 1 - src/LyX.cpp | 11 +++--- src/ParagraphMetrics.cpp | 1 - src/ServerSocket.cpp | 4 ++- src/frontends/Application.h | 6 ++-- src/frontends/qt4/GuiApplication.cpp | 1 - src/frontends/qt4/Toolbars.cpp | 2 -- src/graphics/GraphicsCacheItem.cpp | 4 ++- src/insets/ExternalTransforms.cpp | 2 +- src/insets/ExternalTransforms.h | 17 +++++----- src/insets/InsetText.cpp | 4 +-- src/support/ForkedCalls.cpp | 5 ++- 16 files changed, 47 insertions(+), 75 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 12e3400f7c..08f31484fe 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2218,8 +2218,8 @@ void Buffer::validate(LaTeXFeatures & features) const if (!features.runparams().is_child) params().validate(features); - for_each(paragraphs().begin(), paragraphs().end(), - bind(&Paragraph::validate, _1, ref(features))); + for (Paragraph const & p : paragraphs()) + p.validate(features); if (lyxerr.debugging(Debug::LATEX)) { features.showStruct(); diff --git a/src/Buffer.h b/src/Buffer.h index f488c4a4e0..7acf1f3042 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -687,7 +687,7 @@ private: ExportStatus doExport(std::string const & target, bool put_in_tempdir, bool includeall, std::string & result_file) const; /// - ExportStatus preview(std::string const & format, bool includeall = false) const; + ExportStatus preview(std::string const & format, bool includeall) const; /// void setMathFlavor(OutputParams & op) const; diff --git a/src/BufferList.cpp b/src/BufferList.cpp index 9a5c4e1c27..0b76f13b87 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -32,10 +32,8 @@ #include "support/Package.h" #include "support/lassert.h" -#include "support/bind.h" #include -#include #include #include @@ -277,55 +275,34 @@ bool BufferList::isOthersChild(Buffer * parent, Buffer * child) Buffer const * parent_ = child->parent(); if (parent_ && parent_ != parent) return true; - - BufferStorage::iterator it = bstore.begin(); - BufferStorage::iterator end = bstore.end(); - for (; it != end; ++it) { - Buffer * buf = *it; + + for(Buffer * buf : bstore) if (buf != parent && buf->isChild(child)) return true; - } return false; } -namespace { - -struct equivalent_to : public binary_function -{ - bool operator()(FileName const & x, FileName const & y) const - { return equivalent(x, y); } -}; - -} - - Buffer * BufferList::getBuffer(support::FileName const & fname, bool internal) const { // 1) cheap test, using string comparison of file names - BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(), - lyx::bind(equal_to(), lyx::bind(&Buffer::fileName, _1), fname)); - if (it != bstore.end()) - return *it; + for (Buffer * b : bstore) + if (b->fileName() == fname) + return b; // 2) possibly expensive test, using equivalence test of file names - it = find_if(bstore.begin(), bstore.end(), - lyx::bind(equivalent_to(), lyx::bind(&Buffer::fileName, _1), fname)); - if (it != bstore.end()) - return *it; - + for (Buffer * b : bstore) + if (equivalent(b->fileName(), fname)) + return b; if (internal) { // 1) cheap test, using string comparison of file names - BufferStorage::const_iterator it = find_if(binternal.begin(), binternal.end(), - lyx::bind(equal_to(), lyx::bind(&Buffer::fileName, _1), fname)); - if (it != binternal.end()) - return *it; + for (Buffer * b : binternal) + if (b->fileName() == fname) + return b; // 2) possibly expensive test, using equivalence test of file names - it = find_if(binternal.begin(), binternal.end(), - lyx::bind(equivalent_to(), lyx::bind(&Buffer::fileName, _1), fname)); - if (it != binternal.end()) - return *it; + for (Buffer * b : binternal) + if (equivalent(b->fileName(), fname)) + return b; } - return 0; } diff --git a/src/Cursor.cpp b/src/Cursor.cpp index baf529bfc8..2894f9d71f 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -51,8 +51,6 @@ #include "mathed/MathData.h" #include "mathed/MathMacro.h" -#include "support/bind.h" - #include #include #include @@ -1184,9 +1182,8 @@ void Cursor::plainInsert(MathAtom const & t) void Cursor::insert(docstring const & str) { - for_each(str.begin(), str.end(), - bind(static_cast - (&Cursor::insert), this, _1)); + for (char_type c : str) + insert(c); } diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp index 8cca663c4b..771a9c4926 100644 --- a/src/LayoutFile.cpp +++ b/src/LayoutFile.cpp @@ -27,7 +27,6 @@ #include "support/lassert.h" #include "support/lstrings.h" -#include "support/bind.h" #include "support/regex.h" #include "support/TempFile.h" diff --git a/src/LyX.cpp b/src/LyX.cpp index 66ff6f3dbe..a732c7ee80 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -50,7 +50,6 @@ #include "frontends/alert.h" #include "frontends/Application.h" -#include "support/bind.h" #include "support/ConsoleApplication.h" #include "support/lassert.h" #include "support/debug.h" @@ -65,8 +64,9 @@ #include "support/unique_ptr.h" #include -#include #include +#include +#include #include #include #include @@ -492,9 +492,8 @@ int LyX::execWithoutGui(int & argc, char * argv[]) LYXERR(Debug::FILES, "Loading " << fname); if (buf && buf->loadLyXFile() == Buffer::ReadSuccess) { ErrorList const & el = buf->errorList("Parse"); - if (!el.empty()) - for_each(el.begin(), el.end(), - bind(&LyX::printError, this, _1)); + for(ErrorItem const & e : el) + printError(e); command_line_buffers.push_back(buf); } else { if (buf) @@ -1109,7 +1108,7 @@ bool LyX::readEncodingsFile(string const & enc_name, namespace { /// return the the number of arguments consumed -typedef boost::function cmd_helper; +typedef function cmd_helper; int parse_dbg(string const & arg, string const &, string &) { diff --git a/src/ParagraphMetrics.cpp b/src/ParagraphMetrics.cpp index 1fd248f663..01db6cb934 100644 --- a/src/ParagraphMetrics.cpp +++ b/src/ParagraphMetrics.cpp @@ -47,7 +47,6 @@ #include "support/lstrings.h" #include "support/textutils.h" -#include "support/bind.h" #include #include diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index 72a70d4eda..ece3549a81 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -26,11 +26,13 @@ #include "support/debug.h" #include "support/environment.h" #include "support/FileName.h" +#include "support/lassert.h" #include "support/socktools.h" -#include "support/bind.h" +#include #include +#include #include #if defined (_WIN32) diff --git a/src/frontends/Application.h b/src/frontends/Application.h index df0be95493..b321052ddb 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -18,7 +18,7 @@ #include "support/strfwd.h" -#include +#include #include @@ -216,12 +216,12 @@ public: * passing Color_white returns "ffffff". */ virtual std::string const hexName(ColorCode col) = 0; - + /** * add a callback for socket read notification * @param fd socket descriptor (file/socket/etc) */ - typedef boost::function SocketCallback; + typedef std::function SocketCallback; virtual void registerSocketCallback(int fd, SocketCallback func) = 0; /** diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index eb8c305514..074492b3d3 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -146,7 +146,6 @@ #include #endif // Q_OS_MAC -#include "support/bind.h" #include #include diff --git a/src/frontends/qt4/Toolbars.cpp b/src/frontends/qt4/Toolbars.cpp index 20eee931bc..19b956090e 100644 --- a/src/frontends/qt4/Toolbars.cpp +++ b/src/frontends/qt4/Toolbars.cpp @@ -23,8 +23,6 @@ #include "support/gettext.h" #include "support/lstrings.h" -#include "support/bind.h" - #include using namespace std; diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index 1a7279cba7..ea59173eff 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -26,6 +26,7 @@ #include "support/filetools.h" #include "support/FileMonitor.h" #include "support/lassert.h" +#include "support/unique_ptr.h" #include "support/bind.h" #include "support/TempFile.h" @@ -437,7 +438,8 @@ void CacheItem::Impl::convertToDisplayFormat() // Connect a signal to this->imageConverted and pass this signal to // the graphics converter so that we can load the modified file // on completion of the conversion process. - converter_.reset(new Converter(filename, to_file_base.absFileName(), from, to_)); + converter_ = make_unique(filename, to_file_base.absFileName(), + from, to_); converter_->connect(bind(&Impl::imageConverted, this, _1)); converter_->startConversion(); } diff --git a/src/insets/ExternalTransforms.cpp b/src/insets/ExternalTransforms.cpp index ee31e1911f..7ac41ab02d 100644 --- a/src/insets/ExternalTransforms.cpp +++ b/src/insets/ExternalTransforms.cpp @@ -338,7 +338,7 @@ void extractIt(boost::any const & any_factory, return; Factory factory = boost::any_cast(any_factory); - if (!factory.empty()) + if (!factory) transformer = factory(data); } diff --git a/src/insets/ExternalTransforms.h b/src/insets/ExternalTransforms.h index 1d819001a5..cd3e5e226a 100644 --- a/src/insets/ExternalTransforms.h +++ b/src/insets/ExternalTransforms.h @@ -19,11 +19,12 @@ #include "support/unique_ptr.h" #include -#include -#include +#include #include #include +#include + namespace lyx { @@ -317,17 +318,17 @@ enum TransformID { }; -typedef boost::function +typedef std::function ClipOptionFactory; -typedef boost::function +typedef std::function ExtraOptionFactory; -typedef boost::function +typedef std::function ResizeOptionFactory; -typedef boost::function +typedef std::function RotationOptionFactory; -typedef boost::function +typedef std::function ResizeCommandFactory; -typedef boost::function +typedef std::function RotationCommandFactory; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 53115277a1..216b9c9f97 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -423,8 +423,8 @@ void InsetText::rejectChanges() void InsetText::validate(LaTeXFeatures & features) const { features.useInsetLayout(getLayout()); - for_each(paragraphs().begin(), paragraphs().end(), - bind(&Paragraph::validate, _1, ref(features))); + for (Paragraph const & p : paragraphs()) + p.validate(features); } diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp index fc2b599484..4827947d37 100644 --- a/src/support/ForkedCalls.cpp +++ b/src/support/ForkedCalls.cpp @@ -47,7 +47,6 @@ using namespace std; - namespace lyx { namespace support { @@ -475,7 +474,7 @@ void callNext() Process pro = callQueue_.front(); callQueue_.pop(); // Bind our chain caller - pro.second->connect(lyx::bind(&ForkedCallQueue::callback, _1, _2)); + pro.second->connect(callback); ForkedCall call; //If we fail to fork the process, then emit the signal //to tell the outside world that it failed. @@ -553,7 +552,7 @@ string const getChildErrorMessage() namespace ForkedCallsController { -typedef std::shared_ptr ForkedProcessPtr; +typedef shared_ptr ForkedProcessPtr; typedef list ListType; typedef ListType::iterator iterator;