Skip to content

Commit

Permalink
STYLE: Pass numeric parameters by (const) value, not by const reference
Browse files Browse the repository at this point in the history
Removed the ampersand (`&`) from declarations of "in" (`const`) numeric
parameters (`int`, `unsigned int`, `long`, `unsigned long`, `long long`,
`unsigned long long`, `signed char`, `unsigned char`, `float`, `double`)
of non-virtual member functions and non-member functions.

Following C++ Core Guidelines, April 10, 2022, "For “in” parameters, pass
cheaply-copied types by value and others by reference to `const`":
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f16-for-in-parameters-pass-cheaply-copied-types-by-value-and-others-by-reference-to-const
  • Loading branch information
N-Dekker authored and hjmjohnson committed Jun 2, 2022
1 parent c9a24b1 commit a2e5248
Show file tree
Hide file tree
Showing 35 changed files with 134 additions and 134 deletions.
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkCompensatedSummation.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ class ITK_TEMPLATE_EXPORT CompensatedSummation
};

void ITKCommon_EXPORT
CompensatedSummationAddElement(float & compensation, float & sum, const float & element);
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
void ITKCommon_EXPORT
CompensatedSummationAddElement(double & compensation, double & sum, const double & element);
CompensatedSummationAddElement(double & compensation, double & sum, const double element);

} // end namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkCompensatedSummation.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace itk
{

void ITKCommon_EXPORT
CompensatedSummationAddElement(float & compensation, float & sum, const float & element);
CompensatedSummationAddElement(float & compensation, float & sum, const float element);
void ITKCommon_EXPORT
CompensatedSummationAddElement(double & compensation, double & sum, const double & element);
CompensatedSummationAddElement(double & compensation, double & sum, const double element);

#ifndef itkCompensatedSummation_cxx
// We try the looser pragma guards if we don't have an explicit instantiation.
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkDerivativeOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ITK_TEMPLATE_EXPORT DerivativeOperator : public NeighborhoodOperator<TPixe

/** Sets the order of the derivative. */
void
SetOrder(const unsigned int & order)
SetOrder(const unsigned int order)
{
this->m_Order = order;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkGaussianOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ITK_TEMPLATE_EXPORT GaussianOperator : public NeighborhoodOperator<TPixel,

/** Sets the desired variance of the Gaussian kernel. */
void
SetVariance(const double & variance)
SetVariance(const double variance)
{
m_Variance = variance;
}
Expand All @@ -88,7 +88,7 @@ class ITK_TEMPLATE_EXPORT GaussianOperator : public NeighborhoodOperator<TPixel,
* and the area under the continuous Gaussian. Maximum error affects the
* Gaussian operator size. The value must be between 0.0 and 1.0. */
void
SetMaximumError(const double & max_error)
SetMaximumError(const double max_error)
{
if (max_error >= 1 || max_error <= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,23 @@ class ITKCommon_EXPORT MersenneTwisterRandomVariateGenerator : public RandomVari

/** Get a random variate in the range [0, n] */
double
GetVariateWithClosedRange(const double & n);
GetVariateWithClosedRange(const double n);

/** Get a range variate in the range [0, 1) */
double
GetVariateWithOpenUpperRange();

/** Get a range variate in the range [0, n) */
double
GetVariateWithOpenUpperRange(const double & n);
GetVariateWithOpenUpperRange(const double n);

/** Get a range variate in the range (0, 1) */
double
GetVariateWithOpenRange();

/** Get a range variate in the range (0, n) */
double
GetVariateWithOpenRange(const double & n);
GetVariateWithOpenRange(const double n);

/** Get an integer variate in [0, 2^32-1] */
IntegerType
Expand All @@ -211,12 +211,12 @@ class ITKCommon_EXPORT MersenneTwisterRandomVariateGenerator : public RandomVari
/* Access to a normal random number distribution
* TODO: Compare with vnl_sample_normal */
double
GetNormalVariate(const double & mean = 0.0, const double & variance = 1.0);
GetNormalVariate(const double mean = 0.0, const double variance = 1.0);

/* Access to a uniform random number distribution in the range [a, b)
* TODO: Compare with vnl_sample_uniform */
double
GetUniformVariate(const double & a, const double & b);
GetUniformVariate(const double a, const double b);

/** Get a variate in the range [0, 1]
* Do NOT use for CRYPTOGRAPHY without securely hashing several returned
Expand Down Expand Up @@ -435,7 +435,7 @@ MersenneTwisterRandomVariateGenerator::GetVariateWithClosedRange()

/** Get a random variate in the range [0, n] */
inline double
MersenneTwisterRandomVariateGenerator::GetVariateWithClosedRange(const double & n)
MersenneTwisterRandomVariateGenerator::GetVariateWithClosedRange(const double n)
{
return GetVariateWithClosedRange() * n;
}
Expand All @@ -449,7 +449,7 @@ MersenneTwisterRandomVariateGenerator::GetVariateWithOpenUpperRange()

/** Get a range variate in the range [0, n) */
inline double
MersenneTwisterRandomVariateGenerator::GetVariateWithOpenUpperRange(const double & n)
MersenneTwisterRandomVariateGenerator::GetVariateWithOpenUpperRange(const double n)
{
return GetVariateWithOpenUpperRange() * n;
}
Expand All @@ -463,7 +463,7 @@ MersenneTwisterRandomVariateGenerator::GetVariateWithOpenRange()

/** Get a range variate in the range (0, n) */
inline double
MersenneTwisterRandomVariateGenerator::GetVariateWithOpenRange(const double & n)
MersenneTwisterRandomVariateGenerator::GetVariateWithOpenRange(const double n)
{
return GetVariateWithOpenRange() * n;
}
Expand Down Expand Up @@ -504,7 +504,7 @@ MersenneTwisterRandomVariateGenerator::Get53BitVariate()
/** Access to a normal random number distribution. */
// TODO: Compare with vnl_sample_normal
inline double
MersenneTwisterRandomVariateGenerator::GetNormalVariate(const double & mean, const double & variance)
MersenneTwisterRandomVariateGenerator::GetNormalVariate(const double mean, const double variance)
{
// Return a real number from a normal (Gaussian) distribution with given
// mean and variance by Box-Muller method
Expand All @@ -517,7 +517,7 @@ MersenneTwisterRandomVariateGenerator::GetNormalVariate(const double & mean, con
/** Access to a uniform random number distribution */
// TODO: Compare with vnl_sample_uniform
inline double
MersenneTwisterRandomVariateGenerator::GetUniformVariate(const double & a, const double & b)
MersenneTwisterRandomVariateGenerator::GetUniformVariate(const double a, const double b)
{
double u = GetVariateWithOpenUpperRange();

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkNeighborhoodOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ITK_TEMPLATE_EXPORT NeighborhoodOperator : public Neighborhood<TPixel, VDi

/** Sets the dimensional direction of a directional operator. */
void
SetDirection(const unsigned long & direction)
SetDirection(const unsigned long direction)
{
m_Direction = direction;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/src/itkCompensatedSummation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ namespace itk
{

void ITKCommon_EXPORT
CompensatedSummationAddElement(float & compensation, float & sum, const float & element)
CompensatedSummationAddElement(float & compensation, float & sum, const float element)
{
CompensatedSummationAddElement(compensation, sum, element, 1);
}
void ITKCommon_EXPORT
CompensatedSummationAddElement(double & compensation, double & sum, const double & element)
CompensatedSummationAddElement(double & compensation, double & sum, const double element)
{
CompensatedSummationAddElement(compensation, sum, element, 1);
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkExceptionObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ mammal::operator==(mammal & o)
}

int
lookup(const int & i)
lookup(const int i)
{
static int table[5] = { 23, 42, 42, 32, 12 };
if (!(0 <= i && i < 5))
{
itk::RangeError e(__FILE__, __LINE__);
e.SetLocation("int lookup(const int& )");
e.SetLocation("int lookup(const int )");
e.SetDescription("Attempted to access out-of-bounds array element");
throw e;
}
Expand Down
80 changes: 40 additions & 40 deletions Modules/Core/Mesh/test/itkBinaryMask3DMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ using PixelType = ImageType::PixelType;
using ImagePointerType = ImageType::Pointer;

void
CreateCubeConfig(ImagePointerType image,
const unsigned int & StartX,
const unsigned int & StartY,
const unsigned int & StartZ,
const unsigned char & value1,
const unsigned char & value2,
const unsigned char & value3,
const unsigned char & value4,
const unsigned char & value5,
const unsigned char & value6,
const unsigned char & value7,
const unsigned char & value8);
CreateCubeConfig(ImagePointerType image,
const unsigned int StartX,
const unsigned int StartY,
const unsigned int StartZ,
const unsigned char value1,
const unsigned char value2,
const unsigned char value3,
const unsigned char value4,
const unsigned char value5,
const unsigned char value6,
const unsigned char value7,
const unsigned char value8);

void
Create16CubeConfig(ImagePointerType image,
const unsigned int & StartX,
const unsigned int & StartY,
const unsigned int & StartZ,
const unsigned char & value1,
const unsigned char & value2,
const unsigned char & value3,
const unsigned char & value4);
Create16CubeConfig(ImagePointerType image,
const unsigned int StartX,
const unsigned int StartY,
const unsigned int StartZ,
const unsigned char value1,
const unsigned char value2,
const unsigned char value3,
const unsigned char value4);

int
itkBinaryMask3DMeshSourceTest(int argc, char * argv[])
Expand Down Expand Up @@ -131,18 +131,18 @@ itkBinaryMask3DMeshSourceTest(int argc, char * argv[])
}

void
CreateCubeConfig(ImagePointerType image,
const unsigned int & StartX,
const unsigned int & StartY,
const unsigned int & StartZ,
const unsigned char & value1,
const unsigned char & value2,
const unsigned char & value3,
const unsigned char & value4,
const unsigned char & value5,
const unsigned char & value6,
const unsigned char & value7,
const unsigned char & value8)
CreateCubeConfig(ImagePointerType image,
const unsigned int StartX,
const unsigned int StartY,
const unsigned int StartZ,
const unsigned char value1,
const unsigned char value2,
const unsigned char value3,
const unsigned char value4,
const unsigned char value5,
const unsigned char value6,
const unsigned char value7,
const unsigned char value8)
{
IndexType index;

Expand Down Expand Up @@ -196,14 +196,14 @@ CreateCubeConfig(ImagePointerType image,
}

void
Create16CubeConfig(ImagePointerType image,
const unsigned int & StartX,
const unsigned int & StartY,
const unsigned int & StartZ,
const unsigned char & value1,
const unsigned char & value2,
const unsigned char & value3,
const unsigned char & value4)
Create16CubeConfig(ImagePointerType image,
const unsigned int StartX,
const unsigned int StartY,
const unsigned int StartZ,
const unsigned char value1,
const unsigned char value2,
const unsigned char value3,
const unsigned char value4)
{
// Case 0
CreateCubeConfig(image, StartX + 0, StartY + 0, StartZ + 0, value1, value2, value3, value4, 0, 0, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AssertTopologicalInvariants(TMesh * mesh,
//----------------------------------------------------------------------------
template <typename TMesh>
std::vector<typename TMesh::PointType>
GeneratePointCoordinates(const unsigned int & iN)
GeneratePointCoordinates(const unsigned int iN)
{
using PointType = typename TMesh::PointType;
using CoordRepType = typename PointType::CoordRepType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ITK_TEMPLATE_EXPORT AnisotropicDiffusionFunction : public FiniteDifference

/** Set/Get the conductance parameter. The conductance parameter. */
void
SetConductanceParameter(const double & c)
SetConductanceParameter(const double c)
{
m_ConductanceParameter = c;
}
Expand All @@ -206,7 +206,7 @@ class ITK_TEMPLATE_EXPORT AnisotropicDiffusionFunction : public FiniteDifference
}

void
SetAverageGradientMagnitudeSquared(const double & c)
SetAverageGradientMagnitudeSquared(const double c)
{
m_AverageGradientMagnitudeSquared = c;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkFFTWGlobalConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
* FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE
*/
static void
SetPlanRigor(const int & v);
SetPlanRigor(const int v);

static int
GetPlanRigor();
Expand All @@ -250,7 +250,7 @@ class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object

/** Translate plan rigor value to name. An exception is sent if the value is not valid. */
static std::string
GetPlanRigorName(const int & value);
GetPlanRigorName(const int value);

/**
* \brief Set/Get the behavior of wisdom file caching
Expand Down
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/src/itkFFTWGlobalConfiguration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ FFTWGlobalConfiguration::GetPlanRigorValue(const std::string & name)
}

std::string
FFTWGlobalConfiguration::GetPlanRigorName(const int & value)
FFTWGlobalConfiguration::GetPlanRigorName(const int value)
{
switch (value)
{
Expand Down Expand Up @@ -758,7 +758,7 @@ FFTWGlobalConfiguration::GetNewWisdomAvailable()
}

void
FFTWGlobalConfiguration::SetPlanRigor(const int & v)
FFTWGlobalConfiguration::SetPlanRigor(const int v)
{
itkInitGlobalsMacro(PimplGlobals);
// use that method to check the value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingExtensionImageFilterBase : public FastMarc

/** Get one of the extended auxiliary variable image. */
AuxImageType *
GetAuxiliaryImage(const unsigned int & idx);
GetAuxiliaryImage(const unsigned int idx);

/** Set the container auxiliary values at the initial alive points. */
itkSetObjectMacro(AuxiliaryAliveValues, AuxValueContainerType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FastMarchingExtensionImageFilterBase<TInput, TOutput, TAuxValue, VAuxDimension>:
template <typename TInput, typename TOutput, typename TAuxValue, unsigned int VAuxDimension>
typename FastMarchingExtensionImageFilterBase<TInput, TOutput, TAuxValue, VAuxDimension>::AuxImageType *
FastMarchingExtensionImageFilterBase<TInput, TOutput, TAuxValue, VAuxDimension>::GetAuxiliaryImage(
const unsigned int & idx)
const unsigned int idx)
{
if (idx >= AuxDimension || this->GetNumberOfIndexedOutputs() < idx + 2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ITK_TEMPLATE_EXPORT GPUAnisotropicDiffusionFunction : public GPUFiniteDiff

/** Set/Get the conductance parameter. The conductance parameter. */
void
SetConductanceParameter(const double & c)
SetConductanceParameter(const double c)
{
m_ConductanceParameter = c;
}
Expand All @@ -105,7 +105,7 @@ class ITK_TEMPLATE_EXPORT GPUAnisotropicDiffusionFunction : public GPUFiniteDiff
}

void
SetAverageGradientMagnitudeSquared(const double & c)
SetAverageGradientMagnitudeSquared(const double c)
{
m_AverageGradientMagnitudeSquared = c;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ImagePattern
}

double
Evaluate(const IndexType & index, const SizeType & size, const SizeType & clampSize, const float & padValue)
Evaluate(const IndexType & index, const SizeType & size, const SizeType & clampSize, const float padValue)
{
double accum = m_Offset;
for (int j = 0; j < VDimension; ++j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ITK_TEMPLATE_EXPORT NoiseBaseImageFilter : public InPlaceImageFilter<TInpu

// Clamp and round the input value to the output
static OutputImagePixelType
ClampCast(const double & value);
ClampCast(const double value);

private:
uint32_t m_Seed{ 0 };
Expand Down
Loading

0 comments on commit a2e5248

Please sign in to comment.