Skip to content

Commit

Permalink
STYLE: Use auto for variable type matches
Browse files Browse the repository at this point in the history
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

Remove statements that are not used.

Replace using statements for enums with named enums.
  • Loading branch information
hjmjohnson committed Dec 12, 2024
1 parent 533dc61 commit 0b16b74
Show file tree
Hide file tree
Showing 151 changed files with 461 additions and 489 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkBoundingBox.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ auto
BoundingBox<TPointIdentifier, VPointDimension, TCoordinate, TPointsContainer>::GetDiagonalLength2() const
-> AccumulateType
{
typename NumericTraits<CoordinateType>::AccumulateType dist2 = CoordinateType{};
typename NumericTraits<CoordinateType>::AccumulateType dist2{};

if (this->ComputeBoundingBox())
{
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ ColorTable<TComponent>::UseRandomColors(unsigned int n)
}
for (unsigned int i = 0; i < n; ++i)
{
TComponent r = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
auto r = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][0] = r;
TComponent g = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
auto g = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][1] = g;
TComponent b = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
auto b = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][2] = b;
std::ostringstream name;
name << "Random(" << std::fixed << std::setprecision(2) << static_cast<float>(r) << ',' << static_cast<float>(g)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkCovariantVector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ template <typename T, unsigned int VVectorDimension>
typename CovariantVector<T, VVectorDimension>::ValueType
CovariantVector<T, VVectorDimension>::operator*(const Vector<T, VVectorDimension> & other) const
{
typename NumericTraits<T>::AccumulateType value = T{};
typename NumericTraits<T>::AccumulateType value{};
for (unsigned int i = 0; i < VVectorDimension; ++i)
{
value += (*this)[i] * other[i];
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkGaussianOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GaussianOperator<TPixel, VDimension, TAllocator>::GenerateCoefficients() -> Coef
}
}
// Normalize the coefficients so that their sum is one.
for (typename CoefficientVector::iterator it = coeff.begin(); it < coeff.end(); ++it)
for (auto it = coeff.begin(); it < coeff.end(); ++it)
{
*it /= sum;
}
Expand All @@ -63,7 +63,7 @@ GaussianOperator<TPixel, VDimension, TAllocator>::GenerateCoefficients() -> Coef
coeff.insert(coeff.begin(), j, 0);
{
int i = 0;
for (typename CoefficientVector::iterator it = coeff.end() - 1; i < j; --it, ++i)
for (auto it = coeff.end() - 1; i < j; --it, ++i)
{
coeff[i] = *it;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ namespace itk
#define itkFactorylessNewMacro(x) \
static Pointer New() \
{ \
x * rawPtr = new x(); \
auto * rawPtr = new x(); \
Pointer smartPtr = rawPtr; \
rawPtr->UnRegister(); \
return smartPtr; \
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkNeighborhoodIterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ NeighborhoodIterator<TImage, TBoundaryCondition>::SetPixel(const unsigned int n,
if (!this->m_InBounds[i]) // Part of dimension spills out of bounds
{
const typename OffsetType::OffsetValueType OverlapLow = this->m_InnerBoundsLow[i] - this->m_Loop[i];
const typename OffsetType::OffsetValueType OverlapHigh =
const auto OverlapHigh =
static_cast<OffsetValueType>(this->GetSize(i) - ((this->m_Loop[i] + 2) - this->m_InnerBoundsHigh[i]));
if (temp[i] < OverlapLow || OverlapHigh < temp[i])
{
Expand Down
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkResourceProbesCollectorBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ template <typename TProbe>
void
ResourceProbesCollectorBase<TProbe>::Report(std::ostream & os, bool printSystemInfo, bool printReportHead, bool useTabs)
{
auto probe = this->m_Probes.begin();
const typename MapType::const_iterator end = this->m_Probes.end();
auto probe = this->m_Probes.begin();
const auto end = this->m_Probes.end();

if (probe == end)
{
Expand Down Expand Up @@ -122,8 +122,8 @@ ResourceProbesCollectorBase<TProbe>::ExpandedReport(std::ostream & os,
bool printReportHead,
bool useTabs)
{
auto probe = this->m_Probes.begin();
const typename MapType::const_iterator end = this->m_Probes.end();
auto probe = this->m_Probes.begin();
const auto end = this->m_Probes.end();

if (probe == end)
{
Expand Down Expand Up @@ -174,8 +174,8 @@ template <typename TProbe>
void
ResourceProbesCollectorBase<TProbe>::JSONReport(std::ostream & os, bool printSystemInfo)
{
auto probe = this->m_Probes.begin();
const typename MapType::const_iterator end = this->m_Probes.end();
auto probe = this->m_Probes.begin();
const auto end = this->m_Probes.end();

if (probe == end)
{
Expand Down
5 changes: 2 additions & 3 deletions Modules/Core/Common/include/itkSparseFieldLayer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ auto
SparseFieldLayer<TNodeType>::SplitRegions(int num) const -> RegionListType
{
const unsigned int size = Size();
const unsigned int regionsize =
static_cast<unsigned int>(std::ceil(static_cast<float>(size) / static_cast<float>(num)));
ConstIterator position = Begin();
const auto regionsize = static_cast<unsigned int>(std::ceil(static_cast<float>(size) / static_cast<float>(num)));
ConstIterator position = Begin();
const ConstIterator last = End();

std::vector<RegionType> regionlist;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkThreadLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class ITKCommon_EXPORT ThreadLogger : public Logger
using DelayType = unsigned int;

/** Definition of types of operations for ThreadLogger. */
typedef enum
enum OperationType
{
SET_PRIORITY_LEVEL,
SET_LEVEL_FOR_FLUSHING,
ADD_LOG_OUTPUT,
WRITE,
FLUSH
} OperationType;
};

/** Set the priority level for the current logger. Only messages that have
* priorities equal or greater than the one set here will be posted to the
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkVector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ template <typename T, unsigned int TVectorDimension>
auto
Vector<T, TVectorDimension>::GetSquaredNorm() const -> RealValueType
{
typename NumericTraits<RealValueType>::AccumulateType sum = T{};
auto sum = T{};
for (unsigned int i = 0; i < TVectorDimension; ++i)
{
const RealValueType value = (*this)[i];
Expand Down Expand Up @@ -198,7 +198,7 @@ template <typename T, unsigned int TVectorDimension>
typename Vector<T, TVectorDimension>::ValueType
Vector<T, TVectorDimension>::operator*(const Self & other) const
{
typename NumericTraits<T>::AccumulateType value = T{};
auto value = T{};
for (unsigned int i = 0; i < TVectorDimension; ++i)
{
value += (*this)[i] * other[i];
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/src/itkMetaDataDictionary.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void
MetaDataDictionary::Print(std::ostream & os) const
{
os << "Dictionary use_count: " << m_Dictionary.use_count() << std::endl;
for (MetaDataDictionaryMapType::const_iterator it = m_Dictionary->begin(); it != m_Dictionary->end(); ++it)
for (auto it = m_Dictionary->begin(); it != m_Dictionary->end(); ++it)
{
os << it->first << " ";
it->second->Print(os);
Expand Down Expand Up @@ -102,7 +102,7 @@ MetaDataDictionary::GetKeys() const
using VectorType = std::vector<std::string>;
VectorType ans;

for (MetaDataDictionaryMapType::const_iterator it = m_Dictionary->begin(); it != m_Dictionary->end(); ++it)
for (auto it = m_Dictionary->begin(); it != m_Dictionary->end(); ++it)
{
ans.push_back(it->first);
}
Expand Down Expand Up @@ -179,8 +179,8 @@ MetaDataDictionary::MakeUnique()
bool
MetaDataDictionary::Erase(const std::string & key)
{
auto it = m_Dictionary->find(key);
const MetaDataDictionaryMapType::iterator end = m_Dictionary->end();
auto it = m_Dictionary->find(key);
const auto end = m_Dictionary->end();

if (it != end)
{
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/src/itkObjectFactoryBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class ObjectFactoryBase::ObjectFactoryBasePrivate : public LightObject
auto
ObjectFactoryBase::GetPimplGlobalsPointer() -> ObjectFactoryBasePrivate *
{
const auto deleteLambda = []() { m_PimplGlobals->UnRegister(); };
ObjectFactoryBasePrivate * globalInstance = Singleton<ObjectFactoryBasePrivate>("ObjectFactoryBase", deleteLambda);
const auto deleteLambda = []() { m_PimplGlobals->UnRegister(); };
auto * globalInstance = Singleton<ObjectFactoryBasePrivate>("ObjectFactoryBase", deleteLambda);
if (globalInstance != m_PimplGlobals)
{
SynchronizeObjectFactoryBase(globalInstance);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkProcessObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ ProcessObject::SetOutput(const DataObjectIdentifierType & name, DataObject * out
}

// does this change anything?
const DataObjectPointerMap::const_iterator it = m_Outputs.find(key);
const auto it = m_Outputs.find(key);
if (it != m_Outputs.end() && it->second.GetPointer() == output)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ itkConstShapedNeighborhoodIteratorTest(int, char *[])
std::cout << "it.GetActiveIndexListSize()=" << it.GetActiveIndexListSize();

println("Testing GetActiveIndexList()");
itk::ConstShapedNeighborhoodIterator<TestImageType>::IndexListType l = it.GetActiveIndexList();
itk::ConstShapedNeighborhoodIterator<TestImageType>::IndexListType ::const_iterator ali = l.begin();
itk::ConstShapedNeighborhoodIterator<TestImageType>::IndexListType l = it.GetActiveIndexList();
auto ali = l.begin();
while (ali != l.end())
{
std::cout << *ali << ' ';
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ itkImageTest(int, char *[])
volume->SetRegions(cuboid);

using ProjectionTransformType = TestTransform<Image3D::ImageDimension>;
ProjectionTransformType * projectionTransform = new ProjectionTransformType;
auto * projectionTransform = new ProjectionTransformType;

const Image::RegionType rectangleRegion = itk::ImageAlgorithm::EnlargeRegionOverBox(
volume->GetLargestPossibleRegion(), volume.GetPointer(), imageRef.GetPointer(), projectionTransform);
Expand All @@ -192,7 +192,7 @@ itkImageTest(int, char *[])
}

using TestIdentityTransformType = TestTransform<Image::ImageDimension>;
TestIdentityTransformType * testIdentityTransform = new TestIdentityTransformType;
auto * testIdentityTransform = new TestIdentityTransformType;

const Image::RegionType tesBoxRegion = itk::ImageAlgorithm::EnlargeRegionOverBox(
image->GetLargestPossibleRegion(), image.GetPointer(), imageRef.GetPointer(), testIdentityTransform);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkLineIteratorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ itkLineIteratorTest(int argc, char * argv[])
endIndex.Fill(189);
LineIteratorType it(output, startIndex, endIndex);

std::vector<IndexType>::iterator itBaseline = baselineIndex.begin();
auto itBaseline = baselineIndex.begin();
while (!it.IsAtEnd())
{
it.Set(255);
Expand Down
18 changes: 9 additions & 9 deletions Modules/Core/Common/test/itkMathRoundProfileTest1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ itkMathRoundProfileTest1(int, char *[])
// Count the time of simply assigning values in an std::vector
//
//
IntArrayType::const_iterator outItr1src = output1.begin();
auto outItr2dst = output2.begin();
auto outItr1src = output1.begin();
auto outItr2dst = output2.begin();

const IntArrayType::const_iterator outEnd1 = output1.end();
const auto outEnd1 = output1.end();

chronometer.Start("std::vector");

Expand All @@ -112,8 +112,8 @@ itkMathRoundProfileTest1(int, char *[])

chronometer.Stop("std::vector");

ArrayType::const_iterator inpItr = input.begin();
ArrayType::const_iterator inputEnd = input.end();
auto inpItr = input.begin();
auto inputEnd = input.end();

auto outItr1nc = output1.begin();

Expand Down Expand Up @@ -191,11 +191,11 @@ itkMathRoundProfileTest1(int, char *[])
//
// Now test the correctness of the output
//
ArrayType::const_iterator inpItr = input.begin();
const ArrayType::const_iterator inputEnd = input.end();
auto inpItr = input.begin();
const auto inputEnd = input.end();

IntArrayType::const_iterator outItr1 = output1.begin();
IntArrayType::const_iterator outItr2 = output2.begin();
auto outItr1 = output1.begin();
auto outItr2 = output2.begin();

bool roundMismatch = false;

Expand Down
16 changes: 8 additions & 8 deletions Modules/Core/Common/test/itkObjectFactoryOnlyNewTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ itkObjectFactoryOnlyNewTest(int, char *[])
std::cout << " Factory version: " << oneFactory->GetITKSourceVersion() << std::endl
<< " Factory description: " << oneFactory->GetDescription() << std::endl;

std::list<std::string> overrides = oneFactory->GetClassOverrideNames();
std::list<std::string> names = oneFactory->GetClassOverrideWithNames();
std::list<std::string> descriptions = oneFactory->GetClassOverrideDescriptions();
std::list<bool> enableflags = oneFactory->GetEnableFlags();
std::list<std::string>::const_iterator n = names.begin();
std::list<std::string>::const_iterator d = descriptions.begin();
std::list<bool>::const_iterator e = enableflags.begin();
for (std::list<std::string>::const_iterator o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
std::list<std::string> overrides = oneFactory->GetClassOverrideNames();
std::list<std::string> names = oneFactory->GetClassOverrideWithNames();
std::list<std::string> descriptions = oneFactory->GetClassOverrideDescriptions();
std::list<bool> enableflags = oneFactory->GetEnableFlags();
auto n = names.begin();
auto d = descriptions.begin();
auto e = enableflags.begin();
for (auto o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
{
std::cout << " Override " << *o << " with " << *n << std::endl
<< " described as \"" << *d << '"' << std::endl
Expand Down
16 changes: 8 additions & 8 deletions Modules/Core/Common/test/itkObjectFactoryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ itkObjectFactoryTest(int, char *[])
std::cout << " Factory version: " << oneFactory->GetITKSourceVersion() << std::endl
<< " Factory description: " << oneFactory->GetDescription() << std::endl;

std::list<std::string> overrides = oneFactory->GetClassOverrideNames();
std::list<std::string> names = oneFactory->GetClassOverrideWithNames();
std::list<std::string> descriptions = oneFactory->GetClassOverrideDescriptions();
std::list<bool> enableflags = oneFactory->GetEnableFlags();
std::list<std::string>::const_iterator n = names.begin();
std::list<std::string>::const_iterator d = descriptions.begin();
std::list<bool>::const_iterator e = enableflags.begin();
for (std::list<std::string>::const_iterator o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
std::list<std::string> overrides = oneFactory->GetClassOverrideNames();
std::list<std::string> names = oneFactory->GetClassOverrideWithNames();
std::list<std::string> descriptions = oneFactory->GetClassOverrideDescriptions();
std::list<bool> enableflags = oneFactory->GetEnableFlags();
auto n = names.begin();
auto d = descriptions.begin();
auto e = enableflags.begin();
for (auto o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
{
std::cout << " Override " << *o << " with " << *n << std::endl
<< " described as \"" << *d << '"' << std::endl
Expand Down
16 changes: 8 additions & 8 deletions Modules/Core/Common/test/itkObjectFactoryTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ itkObjectFactoryTest2(int argc, char * argv[])
std::cout << " Factory version: " << factory->GetITKSourceVersion() << std::endl
<< " Factory description: " << factory->GetDescription() << std::endl;

std::list<std::string> overrides = factory->GetClassOverrideNames();
std::list<std::string> names = factory->GetClassOverrideWithNames();
std::list<std::string> descriptions = factory->GetClassOverrideDescriptions();
std::list<bool> enableflags = factory->GetEnableFlags();
std::list<std::string>::const_iterator n = names.begin();
std::list<std::string>::const_iterator d = descriptions.begin();
std::list<bool>::const_iterator e = enableflags.begin();
for (std::list<std::string>::const_iterator o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
std::list<std::string> overrides = factory->GetClassOverrideNames();
std::list<std::string> names = factory->GetClassOverrideWithNames();
std::list<std::string> descriptions = factory->GetClassOverrideDescriptions();
std::list<bool> enableflags = factory->GetEnableFlags();
auto n = names.begin();
auto d = descriptions.begin();
auto e = enableflags.begin();
for (auto o = overrides.begin(); o != overrides.end(); ++o, ++n, ++d, ++e)
{
std::cout << " Override " << *o << " with " << *n << std::endl
<< " described as \"" << *d << '"' << std::endl
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkPriorityQueueTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ itkPriorityQueueTest(int, char *[])
sequence.push_back(1.);
sequence.push_back(-1.);

std::list<double>::const_iterator it = sequence.begin();
size_t i = 0;
auto it = sequence.begin();
size_t i = 0;
for (; it != sequence.end(); ++it, ++i)
{
min_priority_queue->Push(MinPQElementType(i, *it));
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/test/itkSTLContainerAdaptorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ itkSTLContainerAdaptorTest(int, char *[])
targetRef.reserve(vectorSource.size());
targetRef.assign(vectorSource.begin(), vectorSource.end());

STLVectorType::const_iterator it = vectorSource.begin();
auto it = vectorSource.begin();
VectorContainerType::ConstIterator cIter = vectorContainer->Begin();
while (it != vectorSource.end() && cIter != vectorContainer->End())
{
Expand Down Expand Up @@ -116,7 +116,7 @@ itkSTLContainerAdaptorTest(int, char *[])
std::cout << "Testing reading assignment... ";
destination.assign(constTargetRef.begin(), constTargetRef.end());

STLVectorType::const_iterator it = destination.begin();
auto it = destination.begin();
VectorContainerType::ConstIterator cIter = vectorContainer->Begin();
while (it != destination.end() && cIter != vectorContainer->End())
{
Expand Down Expand Up @@ -193,7 +193,7 @@ itkSTLContainerAdaptorTest(int, char *[])
targetRef[i] = mapSource[i];
}

STLMapType::const_iterator it = mapSource.begin();
auto it = mapSource.begin();
MapContainerType::ConstIterator cIter = mapContainer->Begin();
while (it != mapSource.end() && cIter != mapContainer->End())
{
Expand Down Expand Up @@ -244,7 +244,7 @@ itkSTLContainerAdaptorTest(int, char *[])
destination[i] = constTargetRef.find(i)->second;
}

STLMapType::const_iterator it = destination.begin();
auto it = destination.begin();
MapContainerType::ConstIterator cIter = mapContainer->Begin();
while (it != destination.end() && cIter != mapContainer->End())
{
Expand Down
Loading

0 comments on commit 0b16b74

Please sign in to comment.