Skip to content

Commit

Permalink
Use std::mem_fn instead of std::mem_fun
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Jun 22, 2013
1 parent 38d4574 commit ca329a7
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/AbstractCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void AbstractCommand::onAbort() {
std::vector<std::string> uris;
uris.reserve(res.size());
std::transform(res.begin(), res.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI));
std::mem_fn(&URIResult::getURI));
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - %lu URIs found.",
getCuid(),
static_cast<unsigned long int>(uris.size())));
Expand Down
2 changes: 1 addition & 1 deletion src/AdaptiveURISelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
std::deque<URIResult> timeouts;
fileEntry->extractURIResult(timeouts, error_code::TIME_OUT);
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI));
std::mem_fn(&URIResult::getURI));

if(A2_LOG_DEBUG_ENABLED) {
for(std::deque<std::string>::const_iterator i = uris.begin(),
Expand Down
4 changes: 2 additions & 2 deletions src/BtLeecherStateChoke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke
(std::vector<PeerEntry>& peerEntries)
{
std::for_each(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::disableOptUnchoking));
std::mem_fn(&PeerEntry::disableOptUnchoking));

std::vector<PeerEntry>::iterator i =
std::partition(peerEntries.begin(), peerEntries.end(),
Expand All @@ -162,7 +162,7 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
{
std::vector<PeerEntry>::iterator rest =
std::partition(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::isRegularUnchoker));
std::mem_fn(&PeerEntry::isRegularUnchoker));

std::sort(peerEntries.begin(), rest);

Expand Down
2 changes: 1 addition & 1 deletion src/BtSeederStateChoke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void BtSeederStateChoke::unchoke

if(round_ < 2) {
std::for_each(peers.begin(), peers.end(),
std::mem_fun_ref(&PeerEntry::disableOptUnchoking));
std::mem_fn(&PeerEntry::disableOptUnchoking));
if(r != peers.end()) {
std::random_shuffle(r, peers.end(),
*SimpleRandomizer::getInstance());
Expand Down
4 changes: 2 additions & 2 deletions src/CookieStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void CookieStorage::DomainEntry::findCookie

bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
{
using namespace std::placeholders;
setLastAccessTime(now);
std::deque<Cookie>::iterator i =
std::find(cookies_.begin(), cookies_.end(), cookie);
Expand All @@ -121,8 +122,7 @@ bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
cookies_.erase
(std::remove_if(cookies_.begin(), cookies_.end(),
std::bind2nd
(std::mem_fun_ref(&Cookie::isExpired), now)),
std::bind(&Cookie::isExpired, _1, now)),
cookies_.end());
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
std::deque<Cookie>::iterator m = std::min_element
Expand Down
5 changes: 1 addition & 4 deletions src/DHTMessageDispatcherImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ DHTMessageDispatcherImpl::sendMessage

void DHTMessageDispatcherImpl::sendMessages()
{
// TODO I can't use bind1st and mem_fun here because bind1st cannot bind a
// function which takes a reference as an argument..
std::deque<std::shared_ptr<DHTMessageEntry> >::iterator itr =
messageQueue_.begin();
auto itr = messageQueue_.begin();
for(; itr != messageQueue_.end(); ++itr) {
if(!sendMessage(*itr)) {
break;
Expand Down
3 changes: 2 additions & 1 deletion src/DefaultPieceStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ namespace {
void unsetExcludedIndexes(BitfieldMan& bitfield,
const std::vector<size_t>& excludedIndexes)
{
using namespace std::placeholders;
std::for_each(excludedIndexes.begin(), excludedIndexes.end(),
std::bind1st(std::mem_fun(&BitfieldMan::unsetBit), &bitfield));
std::bind(&BitfieldMan::unsetBit, &bitfield, _1));
}
} // namespace

Expand Down
9 changes: 3 additions & 6 deletions src/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,12 @@ class SocketEntry {

void processEvents(int events)
{
using namespace std::placeholders;
std::for_each(commandEvents_.begin(), commandEvents_.end(),
std::bind2nd(std::mem_fun_ref
(&CommandEvent::processEvents),
events));
std::bind(&CommandEvent::processEvents, _1, events));
#ifdef ENABLE_ASYNC_DNS
std::for_each(adnsEvents_.begin(), adnsEvents_.end(),
std::bind2nd(std::mem_fun_ref
(&ADNSEvent::processEvents),
events));
std::bind(&ADNSEvent::processEvents, _1, events));
#endif // ENABLE_ASYNC_DNS
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/FileEntry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)

std::vector<std::string> errorUris(uriResults_.size());
std::transform(uriResults_.begin(), uriResults_.end(),
errorUris.begin(), std::mem_fun_ref(&URIResult::getURI));
errorUris.begin(), std::mem_fn(&URIResult::getURI));
std::sort(errorUris.begin(), errorUris.end());
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
errorUris.end());
Expand Down
8 changes: 4 additions & 4 deletions src/RpcMethod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void RpcMethod::gatherRequestOption(Option* option, const Dict* optionsDict)
{
if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getInitialOption),
std::mem_fn(&OptionHandler::getInitialOption),
option, optionParser_);
}
}
Expand All @@ -128,7 +128,7 @@ void RpcMethod::gatherChangeableOption(Option* option, const Dict* optionsDict)
{
if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeOption),
std::mem_fn(&OptionHandler::getChangeOption),
option, optionParser_);
}
}
Expand All @@ -139,7 +139,7 @@ void RpcMethod::gatherChangeableOptionForReserved
{
if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeOptionForReserved),
std::mem_fn(&OptionHandler::getChangeOptionForReserved),
option, optionParser_);
}
}
Expand All @@ -149,7 +149,7 @@ void RpcMethod::gatherChangeableGlobalOption
{
if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeGlobalOption),
std::mem_fn(&OptionHandler::getChangeGlobalOption),
option, optionParser_);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SelectEventPoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void SelectEventPoll::SocketEntry::removeCommandEvent
}
void SelectEventPoll::SocketEntry::processEvents(int events)
{
using namespace std::placeholders;
std::for_each(commandEvents_.begin(), commandEvents_.end(),
std::bind2nd(std::mem_fun_ref(&CommandEvent::processEvents),
events));
std::bind(&CommandEvent::processEvents, _1, events));
}

int accumulateEvent(int events, const SelectEventPoll::CommandEvent& event)
Expand Down
8 changes: 4 additions & 4 deletions src/aria2api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void apiGatherRequestOption(Option* option, const KeyVals& options,
const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getInitialOption),
std::mem_fn(&OptionHandler::getInitialOption),
option, optionParser);
}
} // namespace
Expand All @@ -230,7 +230,7 @@ void apiGatherChangeableOption(Option* option, const KeyVals& options,
const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOption),
std::mem_fn(&OptionHandler::getChangeOption),
option, optionParser);
}
} // namespace
Expand All @@ -241,7 +241,7 @@ void apiGatherChangeableOptionForReserved
const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOptionForReserved),
std::mem_fn(&OptionHandler::getChangeOptionForReserved),
option, optionParser);
}
} // namespace
Expand All @@ -252,7 +252,7 @@ void apiGatherChangeableGlobalOption
const std::shared_ptr<OptionParser>& optionParser)
{
apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeGlobalOption),
std::mem_fn(&OptionHandler::getChangeGlobalOption),
option, optionParser);
}
} // namespace
Expand Down

0 comments on commit ca329a7

Please sign in to comment.