Skip to content

Conversation

ken2812221
Copy link
Contributor

@ken2812221 ken2812221 commented Jul 22, 2018

Replace boost::bind with std::bind

  • In src/rpc/server.cpp, replace std::transform with simple loop.
  • In src/validation.cpp, store the boost::signals2::connection object and use it to disconnect.
  • In src/validationinterface.cpp, use 2 map to store the boost::signals2::scoped_connection object.

@fanquake fanquake changed the title [Refactor] Replace some boost::bind to std::bind refactor: Replace some boost::bind to std::bind Jul 23, 2018
@fanquake
Copy link
Member

Concept ACK

After this boost::bind will still be used by server, scheduler and validation (and associated tests). @ken2812221 Is there a particular reason you haven't removed that usage?

@practicalswift
Copy link
Contributor

Concept ACK, but please remove using namespace std::placeholders;. Reference _N using the fully specified std::placeholders::_N.

See developer notes:

  • Don't import anything into the global namespace (using namespace ...). Use fully specified types such as std::string.

@ken2812221
Copy link
Contributor Author

ken2812221 commented Jul 23, 2018

After this boost::bind will still be used by server, scheduler and validation (and associated tests).
Is there a particular reason you haven't removed that usage?

Those instances cannot be replaced simply boost -> std. I'll try to get rid of those.

please remove using namespace std::placeholders;

Will do

@maflcko
Copy link
Member

maflcko commented Jul 23, 2018

I believe it is acceptable to be using using namespace std::placeholders here, since the alternative would be extremely verbose.

@practicalswift
Copy link
Contributor

practicalswift commented Jul 23, 2018

@MarcoFalke I'm not sure I agree. The verbosity could help remind us that we really should use lambdas where we're currently using std::bind (modulo the few places where that is not technically possible in C++11), no? :-)

@ken2812221
Copy link
Contributor Author

@practicalswift Since @MarcoFalke think that using namespace std::placeholders; is acceptable, I will wait for more comments from other people and decide what to do.

@ken2812221 ken2812221 changed the title refactor: Replace some boost::bind to std::bind refactor: Replace all boost::bind to std::bind Jul 23, 2018
@practicalswift
Copy link
Contributor

practicalswift commented Jul 23, 2018

@ken2812221 OK! :-) Could you try rewriting them as lambdas where appropriate? That would get rid of std::bind too :-)

@ken2812221
Copy link
Contributor Author

@practicalswift Good point! I'll try to use lambda to replace bind

@@ -508,9 +507,10 @@ std::vector<std::string> CRPCTable::listCommands() const
std::vector<std::string> commandList;
typedef std::map<std::string, const CRPCCommand*> commandMap;
Copy link
Contributor

@Empact Empact Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can remove, this is now unreferenced

@Empact
Copy link
Contributor

Empact commented Jul 23, 2018

How about using place = namespace std::placeholders; as an alternative? The calls would be relatively less verbose and would read well, e.g. std::bind(ThreadSafeMessageBox, this, place::_1, place::_2, place::_3). It would avoid polluting the global namespace, and would make the connection more explicit from source to reference.

connections.Broadcast = g_signals.m_internals->Broadcast.connect(std::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
connections.BlockChecked = g_signals.m_internals->BlockChecked.connect(std::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
connections.NewPoWValidBlock = g_signals.m_internals->NewPoWValidBlock.connect(std::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
g_signals.m_wallet_connections.emplace(pwalletIn, connections);
Copy link
Contributor

@Empact Empact Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could std::move connections

connections.ChainStateFlushed.disconnect();
connections.Broadcast.disconnect();
connections.BlockChecked.disconnect();
connections.NewPoWValidBlock.disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could extract these as a method on ValidationInterfaceConnections where it would be more clear whether the method was comprehensive in its disconnecting.

connections.ChainStateFlushed = g_signals.m_internals->ChainStateFlushed.connect(std::bind(&CValidationInterface::ChainStateFlushed, pwalletIn, _1));
connections.Broadcast = g_signals.m_internals->Broadcast.connect(std::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
connections.BlockChecked = g_signals.m_internals->BlockChecked.connect(std::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
connections.NewPoWValidBlock = g_signals.m_internals->NewPoWValidBlock.connect(std::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could extract as a method on ValidationInterfaceConnections

@ken2812221 ken2812221 changed the title refactor: Replace all boost::bind to std::bind wip, refactor: Replace all boost::bind to std::bind Jul 23, 2018
@ken2812221 ken2812221 changed the title wip, refactor: Replace all boost::bind to std::bind refactor: Replace boost::bind to lambda Jul 23, 2018
@promag
Copy link
Contributor

promag commented Jul 24, 2018

Concept ACK.

@@ -6,10 +6,13 @@
#ifndef BITCOIN_VALIDATIONINTERFACE_H
#define BITCOIN_VALIDATIONINTERFACE_H

#include <boost/signals2/signal.hpp>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will slow down the build significantly. So tend to NACK here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@ken2812221 ken2812221 changed the title refactor: Replace boost::bind to lambda refactor: Replace std/boost::bind to lambda Jul 24, 2018
@fanquake fanquake requested a review from theuni July 25, 2018 11:15
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 25, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14464 (refactor: make checkqueue manage the threads by itself (also removed some boost dependencies) by ken2812221)
  • #14384 (Resolve validationinterface circular dependencies by 251Labs)
  • #14035 (Utxoscriptindex by mgrychow)
  • #13751 (Utils and libraries: Drops the boost/algorithm/string/split.hpp dependency by 251Labs)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK cb53b82. Only change is last review is new comment.

@sipa
Copy link
Member

sipa commented Oct 23, 2018

utACK cb53b82

@ryanofsky
Copy link
Contributor

Can this be merged, or does it need more review? I see review from @theuni was requested in github, but I don't know if it's necessary given the other reviews since this change is pretty straightforward.

@fanquake
Copy link
Member

utACK cb53b82

@practicalswift
Copy link
Contributor

utACK cb53b82

@maflcko maflcko merged commit cb53b82 into bitcoin:master Dec 29, 2018
maflcko pushed a commit that referenced this pull request Dec 29, 2018
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
@fanquake fanquake removed the request for review from theuni December 29, 2018 13:28
@ken2812221 ken2812221 deleted the std-bind branch December 29, 2018 18:55
fanquake added a commit to fanquake/bitcoin that referenced this pull request Aug 31, 2020
boost::bind usage was removed in bitcoin#13743. However a new usage snuck in as
part of 2bc4c3e (bitcoin#15225).
fanquake added a commit that referenced this pull request Sep 3, 2020
e36f802 lint: add C++ code linter (fanquake)
c4be50f remove usage of boost::bind (fanquake)

Pull request description:

  `boost::bind` usage was removed in #13743. However a new usage snuck in as
  part of 2bc4c3e (#15225).

ACKs for top commit:
  hebasto:
    ACK e36f802
  practicalswift:
    ACK e36f802 -- patch looks correct

Tree-SHA512: 2b0387c5443c184bcbf7df4849db1ed1296ff82c7b4ff0aff18334a400e56a472a972d18234d3866531a088d7a8da64688e58dc9f15daaad4048697c759d55ce
kwvg added a commit to kwvg/dash that referenced this pull request Jul 13, 2021
-BEGIN VERIFY SCRIPT-
for j in $(seq 1 5)
do
    gsed -i "s/ _${j}/ std::placeholders::_${j}/g" $(git grep --name-only " _${j}" -- '*.cpp' '*.h')
done
gsed -i "s/boost::bind/std::bind/g" $(git grep --name-only boost::bind -- '*.cpp' '*.h')
gsed -i "s/boost::ref/std::ref/g" $(git grep --name-only boost::ref -- '*.cpp' '*.h')
gsed -i '/boost\/bind/d' $(git grep --name-only boost/bind)
-END VERIFY SCRIPT-
kwvg added a commit to kwvg/dash that referenced this pull request Jul 13, 2021
-BEGIN VERIFY SCRIPT-
for j in $(seq 1 5)
do
    gsed -i "s/ _${j}/ std::placeholders::_${j}/g" $(git grep --name-only " _${j}" -- '*.cpp' '*.h')
done
gsed -i "s/boost::bind/std::bind/g" $(git grep --name-only boost::bind -- '*.cpp' '*.h')
gsed -i "s/boost::ref/std::ref/g" $(git grep --name-only boost::ref -- '*.cpp' '*.h')
gsed -i '/boost\/bind/d' $(git grep --name-only boost/bind)
-END VERIFY SCRIPT-
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 2, 2021
… in signal/slot, also prefer range-based loop instead of std::transform

# Conflicts:
#	src/validationinterface.cpp
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 3, 2021
…l/slot, also prefer range-based loop instead of std::transform
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 8, 2021
…l/slot, also prefer range-based loop instead of std::transform
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Aug 11, 2021
…l/slot, also prefer range-based loop instead of std::transform
kwvg pushed a commit to kwvg/dash that referenced this pull request Aug 12, 2021
…l/slot, also prefer range-based loop instead of std::transform
UdjinM6 added a commit to dashpay/dash that referenced this pull request Aug 13, 2021
dzutto pushed a commit to dzutto/dash that referenced this pull request Aug 16, 2021
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
dzutto pushed a commit to dzutto/dash that referenced this pull request Aug 16, 2021
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
dzutto pushed a commit to dzutto/dash that referenced this pull request Aug 16, 2021
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
dzutto pushed a commit to dzutto/dash that referenced this pull request Aug 17, 2021
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
UdjinM6 pushed a commit to dashpay/dash that referenced this pull request Aug 17, 2021
…nd (#4343)

* Merge bitcoin#13743: refactor: Replace boost::bind with std::bind

cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)

Pull request description:

  Replace boost::bind with std::bind

  - In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
  - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
  - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.

Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0

* Replace boost::bind with std::bind and remove Boost.Bind includes

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.