Commit 6621b069 authored by Hans Johnson's avatar Hans Johnson
Browse files

STYLE: Use range-based loops from C++11

C++11 Range based for loops can be used in

Used as a more readable equivalent to the traditional for loop operating over a
range of values, such as all elements in a container, in the forward direction..

Range based loopes are more explicit for only computing the
end location once for containers.
parent cc8fc323
......@@ -3544,9 +3544,8 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
cachename.push_back("D-cache"); // e.g. PA-RISC
this->Features.L1CacheSize = 0;
for (size_t index = 0; index < cachename.size(); index++) {
std::string cacheSize =
this->ExtractValueFromCpuInfoFile(buffer, cachename[index]);
for (auto& index : cachename) {
std::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer, index);
if (!cacheSize.empty()) {
pos = cacheSize.find(" KB");
if (pos != std::string::npos) {
......@@ -4781,8 +4780,8 @@ std::string SystemInformationImplementation::ParseValueFromKStat(
args.reserve(3 + args_string.size());
args.push_back("kstat");
args.push_back("-p");
for (size_t i = 0; i < args_string.size(); ++i) {
args.push_back(args_string[i].c_str());
for (auto& i : args_string) {
args.push_back(i.c_str());
}
args.push_back(nullptr);
......
......@@ -140,13 +140,13 @@ static int testWithNulls()
strings.push_back(std::string("k") + '\0' + '\0');
strings.push_back(std::string("\0\0\0\0", 4) + "lmn" +
std::string("\0\0\0\0", 4));
for (auto it = strings.begin(); it != strings.end(); ++it) {
std::wstring wstr = kwsys::Encoding::ToWide(*it);
for (auto& string : strings) {
std::wstring wstr = kwsys::Encoding::ToWide(string);
std::string str = kwsys::Encoding::ToNarrow(wstr);
std::string s(*it);
std::string s(string);
std::replace(s.begin(), s.end(), '\0', ' ');
std::cout << "'" << s << "' (" << it->size() << ")" << std::endl;
if (str != *it) {
std::cout << "'" << s << "' (" << string.size() << ")" << std::endl;
if (str != string) {
std::replace(str.begin(), str.end(), '\0', ' ');
std::cout << "string with null was different: '" << str << "' ("
<< str.size() << ")" << std::endl;
......
......@@ -33,10 +33,10 @@ static bool test_hash_map()
m[keys[0]] = 1;
m.insert(mtype::value_type(keys[1], 2));
int sum = 0;
for (mtype::iterator mi = m.begin(); mi != m.end(); ++mi) {
std::cout << "Found entry [" << mi->first << "," << mi->second << "]"
for (auto& mi : m) {
std::cout << "Found entry [" << mi.first << "," << mi.second << "]"
<< std::endl;
sum += mi->second;
sum += mi.second;
}
return sum == 3;
}
......@@ -48,9 +48,9 @@ static bool test_hash_set()
s.insert(1);
s.insert(2);
int sum = 0;
for (stype::iterator si = s.begin(); si != s.end(); ++si) {
std::cout << "Found entry [" << *si << "]" << std::endl;
sum += *si;
for (int si : s) {
std::cout << "Found entry [" << si << "]" << std::endl;
sum += si;
}
return sum == 3;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment