Skip to content

Commit 82cbd7b

Browse files
committed
some more modernize
1 parent 350873d commit 82cbd7b

3 files changed

Lines changed: 31 additions & 22 deletions

File tree

inst/include/Rcpp/utils/tinyformat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ void FormatIterator::accept(const T& value)
521521
std::string result = tmpStream.str(); // allocates... yuck.
522522
if(m_extraFlags & Flag_SpacePadPositive)
523523
{
524-
for(size_t i = 0, iend = result.size(); i < iend; ++i)
525-
if(result[i] == '+')
526-
result[i] = ' ';
524+
for(auto & elem : result)
525+
if(elem == '+')
526+
elem = ' ';
527527
}
528528
if((m_extraFlags & Flag_TruncateToPrecision) &&
529529
(int)result.size() > (int)m_out.precision())

src/attributes.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,8 @@ namespace attributes {
944944
rcppInterfacesWarning("No interfaces specified", lineNumber);
945945
}
946946
else {
947-
for (std::size_t i=0; i<params.size(); i++) {
948-
std::string param = params[i].name();
947+
for (auto & params_i : params) {
948+
std::string param = params_i.name();
949949
if (param != kInterfaceR && param != kInterfaceCpp) {
950950
rcppInterfacesWarning(
951951
"Unknown interface '" + param + "'", lineNumber);
@@ -1420,13 +1420,12 @@ namespace attributes {
14201420
// track cppExports and signatures (we use these at the end to
14211421
// generate the ValidateSignature and RegisterCCallable functions)
14221422
if (attributes.hasInterface(kInterfaceCpp)) {
1423-
for (auto
1424-
it = attributes.begin(); it != attributes.end(); ++it) {
1425-
if (it->isExportedFunction()) {
1423+
for (const auto & attribute : attributes) {
1424+
if (attribute.isExportedFunction()) {
14261425
// add it to the list if it's not hidden
1427-
Function fun = it->function().renamedTo(it->exportedName());
1426+
Function fun = attribute.function().renamedTo(attribute.exportedName());
14281427
if (!fun.isHidden())
1429-
cppExports_.push_back(*it);
1428+
cppExports_.push_back(attribute);
14301429
}
14311430
}
14321431
}
@@ -2059,11 +2058,10 @@ namespace attributes {
20592058
const std::string& contextId) {
20602059

20612060
// process each attribute
2062-
for(auto
2063-
it = attributes.begin(); it != attributes.end(); ++it) {
2061+
for(const auto & attribute : attributes) {
20642062

20652063
// alias the attribute and function (bail if not export)
2066-
const Attribute& attribute = *it;
2064+
20672065
if (!attribute.isExportedFunction())
20682066
continue;
20692067
const Function& function = attribute.function();
@@ -2479,10 +2477,10 @@ namespace {
24792477
const std::string& dllInfo) const
24802478
{
24812479
// process each attribute
2482-
for(auto it = attributes.begin(); it != attributes.end(); ++it) {
2480+
for(const auto & attribute : attributes) {
24832481

24842482
// alias the attribute and function (bail if not export)
2485-
const Attribute& attribute = *it;
2483+
24862484
if (!attribute.isExportedFunction()) continue;
24872485
const Function& function = attribute.function();
24882486

@@ -2685,9 +2683,8 @@ BEGIN_RCPP
26852683

26862684
Rcpp::CharacterVector vDepends = Rcpp::as<Rcpp::CharacterVector>(sDepends);
26872685
std::set<std::string> depends;
2688-
for (Rcpp::CharacterVector::iterator
2689-
it = vDepends.begin(); it != vDepends.end(); ++it) {
2690-
depends.insert(std::string(*it));
2686+
for (auto & vDepend : vDepends) {
2687+
depends.insert(std::string(vDepend));
26912688
}
26922689

26932690
std::vector<std::string> cppFiles =

tools/modernize.sh

100644100755
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env sh
2+
13
IN_RCPP=`pwd | grep Rcpp11$`
24
if [ ${#IN_RCPP} == 0 ]; then
35
echo "Error: not in base Rcpp11 directory."
@@ -9,15 +11,25 @@ fi;
911
## the whole patch 'inst/include'
1012
find inst/include -name "*.h" -type f > tools/modernize-include.txt
1113

14+
## NOTE: For some reason, clang-modernize tries to add a second
15+
## set of overrides to Rstreambuf.h, so we exclude it explicitly
16+
17+
## I also currently get assertion errors if I try to use
18+
## '-use-auto', hence I explicitly set some parameters for modernizing
19+
1220
clang-modernize src/*.cpp \
21+
-final-syntax-check \
1322
-include-from=tools/modernize-include.txt \
23+
-exclude="inst/include/Rcpp/iostream/Rstreambuf.h" \
1424
-style="Chromium" \
1525
-risk=risky \
1626
-pass-by-value \
17-
-use-auto \
27+
-loop-convert \
28+
-add-override \
29+
-for-compilers=clang-3.5 \
1830
-- \
1931
-std=c++1y \
20-
-Iinst/include \
21-
-I/Library/Frameworks/R.framework/Headers \
2232
-I/Users/kevinushey/.llvm/libcxx/include \
23-
-nostdinc++
33+
-I/Library/Frameworks/R.framework/Headers \
34+
-Iinst/include
35+

0 commit comments

Comments
 (0)