summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-06-11 21:37:00 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-06-11 21:37:00 +0900
commit8448b5062feb1aa2af9a61adc5153b12e33d7d14 (patch)
treef3b7adb01775e54f810563988bc3d06fd6b3e771
parent2bbec1086d42f066690048ff5890cfeb1cad25e8 (diff)
Use std::begin and std::end
-rw-r--r--src/AbstractCommand.cc22
-rw-r--r--src/AdaptiveURISelector.cc17
-rw-r--r--src/AppleTLSContext.cc14
-rw-r--r--src/AppleTLSSession.cc3
-rw-r--r--src/AsyncNameResolver.cc6
5 files changed, 28 insertions, 34 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index ae7f5b2f..884fa037 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -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);
}
diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc
index 9696e0e8..3c9c8b3a 100644
--- a/src/AdaptiveURISelector.cc
+++ b/src/AdaptiveURISelector.cc
@@ -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;
}
diff --git a/src/AppleTLSContext.cc b/src/AppleTLSContext.cc
index ae72b5b7..e53bd87f 100644
--- a/src/AppleTLSContext.cc
+++ b/src/AppleTLSContext.cc
@@ -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;
diff --git a/src/AppleTLSSession.cc b/src/AppleTLSSession.cc
index 87f57c30..be2c0713 100644
--- a/src/AppleTLSSession.cc
+++ b/src/AppleTLSSession.cc
@@ -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;
}
diff --git a/src/AsyncNameResolver.cc b/src/AsyncNameResolver.cc
index 31b27aa8..34a33dc1 100644
--- a/src/AsyncNameResolver.cc
+++ b/src/AsyncNameResolver.cc
@@ -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;