Skip to content

Commit 55eff3e

Browse files
committed
STYLE: Modernize to C++11 conventions
STYLE: Use auto for variable creation This check is responsible for using the auto type specifier for variable declarations to improve code readability and maintainability. The auto type specifier will only be introduced in situations where the variable type matches the type of the initializer expression. In other words auto should deduce the same type that was originally spelled in the source cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-use-auto -header-filter=.* -fix use auto when declaring iterators use auto when initializing with a cast to avoid duplicating the type name use auto when initializing with a template cast to avoid duplicating the type name use auto when initializing with new to avoid duplicating the type name SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD PERF: Replace explicit return calls of constructor Replaces explicit calls to the constructor in a return with a braced initializer list. This way the return type is not needlessly duplicated in the function definition and the return statement. SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-return-braced-init-list -header-filter=.* -fix PERF: Allow compiler to choose best way to construct a copy With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. This check allows the compiler to take care of choosing the best way to construct the copy. The transformation is usually beneficial when the calling code passes an rvalue and assumes the move construction is a cheap operation. This short example illustrates how the construction of the value happens: class Foo { public: - Foo(const std::string &Copied, const std::string &ReadOnly) - : Copied(Copied), ReadOnly(ReadOnly) {} + Foo(std::string Moved, const std::string &ReadOnly) + : Copied(std::move(Moved)), ReadOnly(ReadOnly) {} private: private: std::string Copied; const std::string &ReadOnly; }; SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-pass-by-value -header-filter=.* -fix STYLE: Use range-based loops from C++11 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. for ( ImageIORegion::IndexType::const_iterator i = this->GetIndex().begin(); i != this->GetIndex().end(); //<- NOTE: Compute end every loop iteration ++i ) for (long i : this->GetIndex()) //<- NOTE: Implicitly only compute end once ==== Explicitly reduce the amount of index computations: (The compiler probably does this too) for(int i = 0; i < 11; i++) { pos[0] = testPoints[i][0]; pos[1] = testPoints[i][1]; ^^^^ for(auto & testPoint : testPoints) { pos[0] = testPoint[0]; pos[1] = testPoint[1]; ==== SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-loop-convert -header-filter=.* -fix
1 parent 5ff0e26 commit 55eff3e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/itkArrivalFunctionToPathFilter.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typename ArrivalFunctionToPathFilter<TInputImage,TOutputPath>::InputImageType *
109109
ArrivalFunctionToPathFilter<TInputImage,TOutputPath>
110110
::ComputeArrivalFunction()
111111
{
112-
InputImageType * function = (InputImageType *)this->ProcessObject::GetInput(0);
112+
auto * function = (InputImageType *)this->ProcessObject::GetInput(0);
113113
return function;
114114
}
115115

include/itkSpeedFunctionToPathFilter.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ SpeedFunctionToPathFilter<TInputImage,TOutputPath>
106106
typename NodeContainer::Pointer targets = NodeContainer::New();
107107
targets->Initialize();
108108

109-
for (typename PointsContainerType::iterator it = PrevFront.begin(); it != PrevFront.end(); it++)
109+
for (auto it = PrevFront.begin(); it != PrevFront.end(); it++)
110110
{
111111
IndexType indexTargetPrevious;
112112
NodeType nodeTargetPrevious;
@@ -117,7 +117,7 @@ SpeedFunctionToPathFilter<TInputImage,TOutputPath>
117117
PrevIndexVec.push_back(indexTargetPrevious);
118118
}
119119

120-
for (typename PointsContainerType::iterator it = NextFront.begin(); it != NextFront.end(); it++)
120+
for (auto it = NextFront.begin(); it != NextFront.end(); it++)
121121
{
122122
IndexType indexTargetNext;
123123
NodeType nodeTargetNext;
@@ -134,7 +134,7 @@ SpeedFunctionToPathFilter<TInputImage,TOutputPath>
134134
PointsContainerType CurrentFront = m_Information[Superclass::m_CurrentOutput]->PeekCurrentFront(); //FrontAndAdvance();
135135
IndexTypeVec CurrentIndexVec(0);
136136

137-
for (typename PointsContainerType::iterator it = CurrentFront.begin(); it != CurrentFront.end(); it++)
137+
for (auto it = CurrentFront.begin(); it != CurrentFront.end(); it++)
138138
{
139139
IndexType indexTrial;
140140
NodeType nodeTrial;
@@ -172,7 +172,7 @@ SpeedFunctionToPathFilter<TInputImage,TOutputPath>
172172
// optimizer will cross over them. This only matters if the seeds are extended
173173
if (CurrentIndexVec.size() > 1)
174174
{
175-
for (typename IndexTypeVec::iterator vi = CurrentIndexVec.begin(); vi != CurrentIndexVec.end(); vi++)
175+
for (auto vi = CurrentIndexVec.begin(); vi != CurrentIndexVec.end(); vi++)
176176
{
177177
m_CurrentArrivalFunction->SetPixel(*vi, 0);
178178
}

test/MinimalPathTest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ int ReadPathFile( const char * PathFilename, typename PathFilterType::Pointer pa
9292
std::vector<itksys::String> parts;
9393
parts = itksys::SystemTools::SplitString( line.c_str(), ']' );
9494
unsigned int numNonNullParts = 0;
95-
for (unsigned int i=0; i<parts.size(); i++)
96-
if ( parts[i].length() != 0 ) numNonNullParts++;
95+
for (auto & part : parts)
96+
if ( part.length() != 0 ) numNonNullParts++;
9797
for (unsigned int i=0; i<numNonNullParts; i++)
9898
{
9999
if ( parts[i].length() != 0 )
@@ -168,7 +168,7 @@ int ReadPathImage( const char * PathImagename, typename PathFilterType::Pointer
168168
info->SetEndPoint(pmap[2]);
169169
pmap.erase(1);
170170
pmap.erase(2);
171-
for (typename PointMapType::iterator pmit = pmap.begin(); pmit != pmap.end(); ++pmit)
171+
for (auto pmit = pmap.begin(); pmit != pmap.end(); ++pmit)
172172
{
173173
info->AddWayPoint(pmit->second);
174174
}

0 commit comments

Comments
 (0)