Use std::begin and std::end

pull/454/head
Tatsuhiro Tsujikawa 2015-06-11 21:37:00 +09:00
parent 2bbec1086d
commit 8448b5062f
5 changed files with 28 additions and 34 deletions

View File

@ -517,14 +517,12 @@ void AbstractCommand::onAbort()
getPieceStorage()->markPiecesDone(0);
std::vector<std::string> uris;
uris.reserve(res.size());
std::transform(res.begin(),
res.end(),
std::back_inserter(uris),
std::transform(std::begin(res), std::end(res), std::back_inserter(uris),
std::mem_fn(&URIResult::getURI));
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - %lu URIs found.",
getCuid(),
static_cast<unsigned long int>(uris.size())));
fileEntry_->addUris(uris.begin(), uris.end());
fileEntry_->addUris(std::begin(uris), std::end(uris));
getSegmentMan()->recognizeSegmentFor(fileEntry_);
}
@ -702,8 +700,8 @@ namespace {
bool inNoProxy(const std::shared_ptr<Request>& req, const std::string& noProxy)
{
std::vector<Scip> entries;
util::splitIter
(noProxy.begin(), noProxy.end(), std::back_inserter(entries), ',', true);
util::splitIter(std::begin(noProxy), std::end(noProxy),
std::back_inserter(entries), ',', true);
if (entries.empty()) {
return false;
}
@ -775,10 +773,8 @@ std::string AbstractCommand::resolveHostname(std::vector<std::string>& addrs,
e_->findAllCachedIPAddresses(std::back_inserter(addrs), hostname, port);
if (!addrs.empty()) {
auto ipaddr = addrs.front();
A2_LOG_INFO(fmt(MSG_DNS_CACHE_HIT,
getCuid(),
hostname.c_str(),
strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
A2_LOG_INFO(fmt(MSG_DNS_CACHE_HIT, getCuid(), hostname.c_str(),
strjoin(std::begin(addrs), std::end(addrs), ", ").c_str()));
return ipaddr;
}
@ -825,10 +821,8 @@ std::string AbstractCommand::resolveHostname(std::vector<std::string>& addrs,
}
res.resolve(addrs, hostname);
}
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
getCuid(),
hostname.c_str(),
strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE, getCuid(), hostname.c_str(),
strjoin(std::begin(addrs), std::end(addrs), ", ").c_str()));
for (const auto& addr : addrs) {
e_->cacheIPAddress(hostname, addr, port);
}

View File

@ -90,9 +90,9 @@ std::string AdaptiveURISelector::select
std::string selected = selectOne(uris);
if(selected != A2STR::NIL)
uris.erase(std::find(uris.begin(), uris.end(), selected));
if(selected != A2STR::NIL) {
uris.erase(std::find(std::begin(uris), std::end(uris), selected));
}
return selected;
}
@ -109,17 +109,16 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
// looking for retries
std::deque<URIResult> timeouts;
fileEntry->extractURIResult(timeouts, error_code::TIME_OUT);
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
std::mem_fn(&URIResult::getURI));
std::transform(std::begin(timeouts), std::end(timeouts),
std::back_inserter(uris), std::mem_fn(&URIResult::getURI));
if(A2_LOG_DEBUG_ENABLED) {
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
for (const auto& uri : uris) {
A2_LOG_DEBUG(
fmt("AdaptiveURISelector: will retry server with increased"
" timeout (%ld s): %s",
static_cast<long int>(requestGroup_->getTimeout().count()),
(*i).c_str()));
uri.c_str()));
}
}
}
@ -305,7 +304,7 @@ std::string AdaptiveURISelector::selectRandomUri
(const std::deque<std::string>& uris) const
{
int pos = SimpleRandomizer::getInstance()->getRandomNumber(uris.size());
auto i = uris.begin();
auto i = std::begin(uris);
i = i+pos;
return *i;
}

View File

@ -111,7 +111,8 @@ static inline bool isWhitespace(char c)
static inline std::string stripWhitespace(std::string str)
{
str.erase(std::remove_if(str.begin(), str.end(), isWhitespace), str.end());
str.erase(std::remove_if(std::begin(str), std::end(str), isWhitespace),
std::end(str));
return str;
}
@ -185,9 +186,9 @@ bool checkIdentity(const SecIdentityRef id,
// future-proof. Also "usually" doesn't cut it; there is already software
// using SHA-2 class algos, and SHA-3 is standardized and potential users
// cannot be far.
return std::find_if(supported.begin(),
supported.end(),
hash_finder(data.get(), fingerPrint)) != supported.end();
return std::find_if(std::begin(supported), std::end(supported),
hash_finder(data.get(), fingerPrint)) !=
std::end(supported);
}
#endif // defined(__MAC_10_6)
@ -243,11 +244,12 @@ bool AppleTLSContext::tryAsFingerprint(const std::string& fingerprint)
{
auto fp = stripWhitespace(fingerprint);
// Verify this is a valid hex representation and normalize.
fp = util::toHex(util::fromHex(fp.begin(), fp.end()));
fp = util::toHex(util::fromHex(std::begin(fp), std::end(fp)));
// Verify this can represent a hash
auto ht = MessageDigest::getSupportedHashTypes();
if (std::find_if(ht.begin(), ht.end(), hash_validator(fp)) == ht.end()) {
if (std::find_if(std::begin(ht), std::end(ht), hash_validator(fp)) ==
std::end(ht)) {
A2_LOG_INFO(fmt("%s is not a fingerprint, invalid hash representation",
fingerprint.c_str()));
return false;

View File

@ -330,7 +330,8 @@ static SSLCipherSuiteList constructEnabledSuites(SSLContextRef ctx)
return rv;
}
rv.erase(std::remove_if(rv.begin(), rv.end(), isBlockedSuite), rv.end());
rv.erase(std::remove_if(std::begin(rv), std::end(rv), isBlockedSuite),
std::end(rv));
return rv;
}

View File

@ -143,10 +143,8 @@ void AsyncNameResolver::reset()
ares_addr_node* parseAsyncDNSServers(const std::string& serversOpt)
{
std::vector<std::string> servers;
util::split(serversOpt.begin(), serversOpt.end(),
std::back_inserter(servers),
',',
true /* doStrip */);
util::split(std::begin(serversOpt), std::end(serversOpt),
std::back_inserter(servers), ',', true /* doStrip */);
ares_addr_node root;
root.next = nullptr;
ares_addr_node* tail = &root;