Skip to content

Commit

Permalink
STYLE: Avoid T var = elementValue syntax to initialize a filled array
Browse files Browse the repository at this point in the history
The C++ copy-initialization syntax `T var = value` suggests that the
value at the right side is implicitly converted to the target type `T`.

When the target type `T` is a `FixedArray<TValue, VLength>`, or one of
its derived types, `T var = elementValue` _fills_ the variable with the
specified `elementValue`, by assigning the `elementValue` to each of its
elements. In this case, the C++ direct-initialization syntax
`T var(elementValue)` appears more appropriate.

Occurrences of `T var = elementValue` were found by locally temporarily
declaring the corresponding constructors `explicit`.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Feb 24, 2022
1 parent 5b71d63 commit 0c6c3a9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ itkEllipseSpatialObjectTest(int, char *[])

ITK_TEST_SET_GET_VALUE(radii, myEllipse->GetRadiusInObjectSpace());

EllipseType::ArrayType objectSpaceRadius = 3;
EllipseType::ArrayType objectSpaceRadius(3);
myEllipse->SetRadiusInObjectSpace(objectSpaceRadius);
myEllipse->Update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ itkCannyEdgeDetectionImageFilterTest(int argc, char * argv[])
filter->SetLowerThreshold(lowerThreshold);
ITK_TEST_SET_GET_VALUE(lowerThreshold, filter->GetLowerThreshold());

CannyEdgeDetectionImageFilterType::ArrayType variance = 1.0f;
CannyEdgeDetectionImageFilterType::ArrayType variance(1.0f);
filter->SetVariance(variance);
ITK_TEST_SET_GET_VALUE(variance, filter->GetVariance());

CannyEdgeDetectionImageFilterType::ArrayType maximumError = .01f;
CannyEdgeDetectionImageFilterType::ArrayType maximumError(.01f);
filter->SetMaximumError(maximumError);
ITK_TEST_SET_GET_VALUE(maximumError, filter->GetMaximumError());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ itkCannyEdgeDetectionImageFilterTest2(int argc, char * argv[])
filter->SetLowerThreshold(lowerThreshold);
ITK_TEST_SET_GET_VALUE(lowerThreshold, filter->GetLowerThreshold());

CannyEdgeDetectionImageFilterType::ArrayType variance = 1.0f;
CannyEdgeDetectionImageFilterType::ArrayType variance(1.0f);
filter->SetVariance(variance);
ITK_TEST_SET_GET_VALUE(variance, filter->GetVariance());

CannyEdgeDetectionImageFilterType::ArrayType maximumError = .01f;
CannyEdgeDetectionImageFilterType::ArrayType maximumError(.01f);
filter->SetMaximumError(maximumError);
ITK_TEST_SET_GET_VALUE(maximumError, filter->GetMaximumError());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BSpline(int argc, char * argv[])
bspliner->SetCloseDimension(closeDimension);
ITK_TEST_SET_GET_VALUE(closeDimension, bspliner->GetCloseDimension());

typename BSplinerType::ArrayType splineOrder = 3;
typename BSplinerType::ArrayType splineOrder(3);
bspliner->SetSplineOrder(splineOrder);
ITK_TEST_SET_GET_VALUE(splineOrder, bspliner->GetSplineOrder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ itkGaborImageSourceTestHelper(char * outputFilename, bool calculcateImaginaryPar
gaborImage->SetSigma(sigma);
ITK_TEST_SET_GET_VALUE(sigma, gaborImage->GetSigma());

typename GaborSourceType::ArrayType mean = 0.1;
typename GaborSourceType::ArrayType mean(0.1);
gaborImage->SetMean(mean);
ITK_TEST_SET_GET_VALUE(mean, gaborImage->GetMean());

Expand Down

0 comments on commit 0c6c3a9

Please sign in to comment.