From 2e050ea744dcc922f925a177aeafc14a396068ee Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 17 May 2017 17:17:51 -0700 Subject: [PATCH] Merge #10395: Replace boost::function with std::function (C++11) 1b936f5 Replace boost::function with std::function (C++11) (practicalswift) Tree-SHA512: c4faec8cf3f801842010976115681f68ffa08fbc97ba50b22e95c936840f47e1b3bd8d7fd2f5b4e094b5a46bf3d29fc90b69d975a99e77322c0d19f8a00d53d3 --- src/bench/bench.cpp | 1 + src/bench/bench.h | 5 +++-- src/httprpc.cpp | 4 ++-- src/init.cpp | 1 - src/qt/rpcconsole.cpp | 12 ++++++------ src/rpc/server.cpp | 8 ++++---- src/rpc/server.h | 12 +++++------- src/scheduler.h | 4 ++-- src/torcontrol.cpp | 9 ++++----- src/txdb.cpp | 2 +- src/txdb.h | 4 +--- 11 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index a9c5571e4..e5fa66890 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -5,6 +5,7 @@ #include "bench.h" #include "perf.h" +#include #include #include #include diff --git a/src/bench/bench.h b/src/bench/bench.h index 5a050a746..fcde850de 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -5,10 +5,11 @@ #ifndef BITCOIN_BENCH_BENCH_H #define BITCOIN_BENCH_BENCH_H +#include +#include #include #include -#include #include #include @@ -59,7 +60,7 @@ namespace benchmark { bool KeepRunning(); }; - typedef boost::function BenchFunction; + typedef std::function BenchFunction; class BenchRunner { diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 7fe821328..df2fb9aae 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -30,7 +30,7 @@ static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; class HTTPRPCTimer : public RPCTimerBase { public: - HTTPRPCTimer(struct event_base* eventBase, boost::function& func, int64_t millis) : + HTTPRPCTimer(struct event_base* eventBase, std::function& func, int64_t millis) : ev(eventBase, false, func) { struct timeval tv; @@ -52,7 +52,7 @@ public: { return "HTTP"; } - RPCTimerBase* NewTimer(boost::function& func, int64_t millis) override + RPCTimerBase* NewTimer(std::function& func, int64_t millis) override { return new HTTPRPCTimer(base, func, millis); } diff --git a/src/init.cpp b/src/init.cpp index 4e1b639d8..86e2ce4ee 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -88,7 +88,6 @@ #include #include #include -#include #include #include #include diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 53bebeace..d99530d53 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -108,7 +108,7 @@ class QtRPCTimerBase: public QObject, public RPCTimerBase { Q_OBJECT public: - QtRPCTimerBase(boost::function& _func, int64_t millis): + QtRPCTimerBase(std::function& _func, int64_t millis): func(_func) { timer.setSingleShot(true); @@ -120,7 +120,7 @@ private Q_SLOTS: void timeout() { func(); } private: QTimer timer; - boost::function func; + std::function func; }; class QtRPCTimerInterface: public RPCTimerInterface @@ -128,7 +128,7 @@ class QtRPCTimerInterface: public RPCTimerInterface public: ~QtRPCTimerInterface() {} const char *Name() override { return "Qt"; } - RPCTimerBase* NewTimer(boost::function& func, int64_t millis) override + RPCTimerBase* NewTimer(std::function& func, int64_t millis) override { return new QtRPCTimerBase(func, millis); } @@ -452,7 +452,7 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) : connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger())); connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller())); connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear())); - + // Wallet Repair Buttons // connect(ui->btn_salvagewallet, SIGNAL(clicked()), this, SLOT(walletSalvage())); // Disable salvage option in GUI, it's way too powerful and can lead to funds loss @@ -774,7 +774,7 @@ void RPCConsole::buildParameterlist(QString arg) args.removeAll(ZAPTXES2); args.removeAll(UPGRADEWALLET); args.removeAll(REINDEX); - + // Append repair parameter to command line. args.append(arg); @@ -797,7 +797,7 @@ void RPCConsole::clear(bool clearHistory) // (when using width/height on an img, Qt uses nearest instead of linear interpolation) QString iconPath = ":/icons/" + GUIUtil::getThemeName() + "/"; QString iconName = ""; - + for(int i=0; ICON_MAPPING[i].url; ++i) { iconName = ICON_MAPPING[i].source; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 3e1f8c182..7033d930f 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -46,17 +46,17 @@ static struct CRPCSignals boost::signals2::signal PreCommand; } g_rpcSignals; -void RPCServer::OnStarted(boost::function slot) +void RPCServer::OnStarted(std::function slot) { g_rpcSignals.Started.connect(slot); } -void RPCServer::OnStopped(boost::function slot) +void RPCServer::OnStopped(std::function slot) { g_rpcSignals.Stopped.connect(slot); } -void RPCServer::OnPreCommand(boost::function slot) +void RPCServer::OnPreCommand(std::function slot) { g_rpcSignals.PreCommand.connect(boost::bind(slot, _1)); } @@ -595,7 +595,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface) timerInterface = NULL; } -void RPCRunLater(const std::string& name, boost::function func, int64_t nSeconds) +void RPCRunLater(const std::string& name, std::function func, int64_t nSeconds) { if (!timerInterface) throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC"); diff --git a/src/rpc/server.h b/src/rpc/server.h index d90846c34..98e2bddbe 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -15,17 +15,15 @@ #include #include -#include - #include class CRPCCommand; namespace RPCServer { - void OnStarted(boost::function slot); - void OnStopped(boost::function slot); - void OnPreCommand(boost::function slot); + void OnStarted(std::function slot); + void OnStopped(std::function slot); + void OnPreCommand(std::function slot); } class CBlockIndex; @@ -113,7 +111,7 @@ public: * This is needed to cope with the case in which there is no HTTP server, but * only GUI RPC console, and to break the dependency of pcserver on httprpc. */ - virtual RPCTimerBase* NewTimer(boost::function& func, int64_t millis) = 0; + virtual RPCTimerBase* NewTimer(std::function& func, int64_t millis) = 0; }; /** Set the factory function for timers */ @@ -127,7 +125,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface); * Run func nSeconds from now. * Overrides previous timer (if any). */ -void RPCRunLater(const std::string& name, boost::function func, int64_t nSeconds); +void RPCRunLater(const std::string& name, std::function func, int64_t nSeconds); typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest); diff --git a/src/scheduler.h b/src/scheduler.h index 613fc1653..27412a15b 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -7,8 +7,8 @@ // // NOTE: -// boost::thread / boost::function / boost::chrono should be ported to -// std::thread / std::function / std::chrono when we support C++11. +// boost::thread / boost::chrono should be ported to std::thread / std::chrono +// when we support C++11. // #include #include diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 91e087bdf..620eaac1b 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -73,8 +72,8 @@ public: class TorControlConnection { public: - typedef boost::function ConnectionCB; - typedef boost::function ReplyHandlerCB; + typedef std::function ConnectionCB; + typedef std::function ReplyHandlerCB; /** Create a new TorControlConnection. */ @@ -105,9 +104,9 @@ public: boost::signals2::signal async_handler; private: /** Callback when ready for use */ - boost::function connected; + std::function connected; /** Callback when connection lost */ - boost::function disconnected; + std::function disconnected; /** Libevent event base */ struct event_base *base; /** Connection to control socket */ diff --git a/src/txdb.cpp b/src/txdb.cpp index 17596e414..944cfcaf1 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -344,7 +344,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) { return true; } -bool CBlockTreeDB::LoadBlockIndexGuts(boost::function insertBlockIndex) +bool CBlockTreeDB::LoadBlockIndexGuts(std::function insertBlockIndex) { std::unique_ptr pcursor(NewIterator()); diff --git a/src/txdb.h b/src/txdb.h index 9e7c5b699..de3a00dce 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -16,8 +16,6 @@ #include #include -#include - class CBlockIndex; class CCoinsViewDBCursor; class uint256; @@ -138,7 +136,7 @@ public: bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector &vect); bool WriteFlag(const std::string &name, bool fValue); bool ReadFlag(const std::string &name, bool &fValue); - bool LoadBlockIndexGuts(boost::function insertBlockIndex); + bool LoadBlockIndexGuts(std::function insertBlockIndex); }; #endif // BITCOIN_TXDB_H