Use std::mem_fn instead of std::mem_fun

pull/103/head
Tatsuhiro Tsujikawa 2013-06-22 19:15:57 +09:00
parent 38d4574355
commit ca329a7ccb
12 changed files with 24 additions and 29 deletions

View File

@ -469,7 +469,7 @@ void AbstractCommand::onAbort() {
std::vector<std::string> uris; std::vector<std::string> uris;
uris.reserve(res.size()); uris.reserve(res.size());
std::transform(res.begin(), res.end(), std::back_inserter(uris), 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.", A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - %lu URIs found.",
getCuid(), getCuid(),
static_cast<unsigned long int>(uris.size()))); static_cast<unsigned long int>(uris.size())));

View File

@ -106,7 +106,7 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
std::deque<URIResult> timeouts; std::deque<URIResult> timeouts;
fileEntry->extractURIResult(timeouts, error_code::TIME_OUT); fileEntry->extractURIResult(timeouts, error_code::TIME_OUT);
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris), 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) { if(A2_LOG_DEBUG_ENABLED) {
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),

View File

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

View File

@ -135,7 +135,7 @@ void BtSeederStateChoke::unchoke
if(round_ < 2) { if(round_ < 2) {
std::for_each(peers.begin(), peers.end(), std::for_each(peers.begin(), peers.end(),
std::mem_fun_ref(&PeerEntry::disableOptUnchoking)); std::mem_fn(&PeerEntry::disableOptUnchoking));
if(r != peers.end()) { if(r != peers.end()) {
std::random_shuffle(r, peers.end(), std::random_shuffle(r, peers.end(),
*SimpleRandomizer::getInstance()); *SimpleRandomizer::getInstance());

View File

@ -111,6 +111,7 @@ void CookieStorage::DomainEntry::findCookie
bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now) bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
{ {
using namespace std::placeholders;
setLastAccessTime(now); setLastAccessTime(now);
std::deque<Cookie>::iterator i = std::deque<Cookie>::iterator i =
std::find(cookies_.begin(), cookies_.end(), cookie); std::find(cookies_.begin(), cookies_.end(), cookie);
@ -121,8 +122,7 @@ bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) { if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
cookies_.erase cookies_.erase
(std::remove_if(cookies_.begin(), cookies_.end(), (std::remove_if(cookies_.begin(), cookies_.end(),
std::bind2nd std::bind(&Cookie::isExpired, _1, now)),
(std::mem_fun_ref(&Cookie::isExpired), now)),
cookies_.end()); cookies_.end());
if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) { if(cookies_.size() >= CookieStorage::MAX_COOKIE_PER_DOMAIN) {
std::deque<Cookie>::iterator m = std::min_element std::deque<Cookie>::iterator m = std::min_element

View File

@ -103,10 +103,7 @@ DHTMessageDispatcherImpl::sendMessage
void DHTMessageDispatcherImpl::sendMessages() void DHTMessageDispatcherImpl::sendMessages()
{ {
// TODO I can't use bind1st and mem_fun here because bind1st cannot bind a auto itr = messageQueue_.begin();
// function which takes a reference as an argument..
std::deque<std::shared_ptr<DHTMessageEntry> >::iterator itr =
messageQueue_.begin();
for(; itr != messageQueue_.end(); ++itr) { for(; itr != messageQueue_.end(); ++itr) {
if(!sendMessage(*itr)) { if(!sendMessage(*itr)) {
break; break;

View File

@ -235,8 +235,9 @@ namespace {
void unsetExcludedIndexes(BitfieldMan& bitfield, void unsetExcludedIndexes(BitfieldMan& bitfield,
const std::vector<size_t>& excludedIndexes) const std::vector<size_t>& excludedIndexes)
{ {
using namespace std::placeholders;
std::for_each(excludedIndexes.begin(), excludedIndexes.end(), std::for_each(excludedIndexes.begin(), excludedIndexes.end(),
std::bind1st(std::mem_fun(&BitfieldMan::unsetBit), &bitfield)); std::bind(&BitfieldMan::unsetBit, &bitfield, _1));
} }
} // namespace } // namespace

View File

@ -290,15 +290,12 @@ public:
void processEvents(int events) void processEvents(int events)
{ {
using namespace std::placeholders;
std::for_each(commandEvents_.begin(), commandEvents_.end(), std::for_each(commandEvents_.begin(), commandEvents_.end(),
std::bind2nd(std::mem_fun_ref std::bind(&CommandEvent::processEvents, _1, events));
(&CommandEvent::processEvents),
events));
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
std::for_each(adnsEvents_.begin(), adnsEvents_.end(), std::for_each(adnsEvents_.begin(), adnsEvents_.end(),
std::bind2nd(std::mem_fun_ref std::bind(&ADNSEvent::processEvents, _1, events));
(&ADNSEvent::processEvents),
events));
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
} }
}; };

View File

@ -403,7 +403,7 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
std::vector<std::string> errorUris(uriResults_.size()); std::vector<std::string> errorUris(uriResults_.size());
std::transform(uriResults_.begin(), uriResults_.end(), 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()); std::sort(errorUris.begin(), errorUris.end());
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()), errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
errorUris.end()); errorUris.end());

View File

@ -119,7 +119,7 @@ void RpcMethod::gatherRequestOption(Option* option, const Dict* optionsDict)
{ {
if(optionsDict) { if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(), gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getInitialOption), std::mem_fn(&OptionHandler::getInitialOption),
option, optionParser_); option, optionParser_);
} }
} }
@ -128,7 +128,7 @@ void RpcMethod::gatherChangeableOption(Option* option, const Dict* optionsDict)
{ {
if(optionsDict) { if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(), gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeOption), std::mem_fn(&OptionHandler::getChangeOption),
option, optionParser_); option, optionParser_);
} }
} }
@ -139,7 +139,7 @@ void RpcMethod::gatherChangeableOptionForReserved
{ {
if(optionsDict) { if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(), gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeOptionForReserved), std::mem_fn(&OptionHandler::getChangeOptionForReserved),
option, optionParser_); option, optionParser_);
} }
} }
@ -149,7 +149,7 @@ void RpcMethod::gatherChangeableGlobalOption
{ {
if(optionsDict) { if(optionsDict) {
gatherOption(optionsDict->begin(), optionsDict->end(), gatherOption(optionsDict->begin(), optionsDict->end(),
std::mem_fun(&OptionHandler::getChangeGlobalOption), std::mem_fn(&OptionHandler::getChangeGlobalOption),
option, optionParser_); option, optionParser_);
} }
} }

View File

@ -106,9 +106,9 @@ void SelectEventPoll::SocketEntry::removeCommandEvent
} }
void SelectEventPoll::SocketEntry::processEvents(int events) void SelectEventPoll::SocketEntry::processEvents(int events)
{ {
using namespace std::placeholders;
std::for_each(commandEvents_.begin(), commandEvents_.end(), std::for_each(commandEvents_.begin(), commandEvents_.end(),
std::bind2nd(std::mem_fun_ref(&CommandEvent::processEvents), std::bind(&CommandEvent::processEvents, _1, events));
events));
} }
int accumulateEvent(int events, const SelectEventPoll::CommandEvent& event) int accumulateEvent(int events, const SelectEventPoll::CommandEvent& event)

View File

@ -220,7 +220,7 @@ void apiGatherRequestOption(Option* option, const KeyVals& options,
const std::shared_ptr<OptionParser>& optionParser) const std::shared_ptr<OptionParser>& optionParser)
{ {
apiGatherOption(options.begin(), options.end(), apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getInitialOption), std::mem_fn(&OptionHandler::getInitialOption),
option, optionParser); option, optionParser);
} }
} // namespace } // namespace
@ -230,7 +230,7 @@ void apiGatherChangeableOption(Option* option, const KeyVals& options,
const std::shared_ptr<OptionParser>& optionParser) const std::shared_ptr<OptionParser>& optionParser)
{ {
apiGatherOption(options.begin(), options.end(), apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOption), std::mem_fn(&OptionHandler::getChangeOption),
option, optionParser); option, optionParser);
} }
} // namespace } // namespace
@ -241,7 +241,7 @@ void apiGatherChangeableOptionForReserved
const std::shared_ptr<OptionParser>& optionParser) const std::shared_ptr<OptionParser>& optionParser)
{ {
apiGatherOption(options.begin(), options.end(), apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeOptionForReserved), std::mem_fn(&OptionHandler::getChangeOptionForReserved),
option, optionParser); option, optionParser);
} }
} // namespace } // namespace
@ -252,7 +252,7 @@ void apiGatherChangeableGlobalOption
const std::shared_ptr<OptionParser>& optionParser) const std::shared_ptr<OptionParser>& optionParser)
{ {
apiGatherOption(options.begin(), options.end(), apiGatherOption(options.begin(), options.end(),
std::mem_fun(&OptionHandler::getChangeGlobalOption), std::mem_fn(&OptionHandler::getChangeGlobalOption),
option, optionParser); option, optionParser);
} }
} // namespace } // namespace